urlreadpost - url POST method with binary file uploading

버전 1.1.0.0 (3.5 KB) 작성자: Dan Ellis
A replacement for urlread(url,'post',...) that allows POST to upload binary (file) data.
다운로드 수: 2.1K
업데이트 날짜: 2010/4/8

라이선스 보기

The HTTP 'POST' method is provided as a mechanism for uploading data as part of a URL request. There are two methods for encoding this data: application/x-www-form-urlencoded, in which each parameter is inserted as part of one long string, and multipart/form-data, in which each parameter gets its own MIME form-data block in the stream. This latter method allows the inclusion of large amounts of binary data (for instance, a POST which uploads a file) which is not possible with x-www-form-urlencoded.

Matlab's stock urlread does support the 'POST' method, but only with the x-www-form-urlencoded encoding. I wrote this replacement to be able to access web services that involve uploading binary files directly from Matlab. Here's an example, of uploading MP3 audio data to the Echo Nest Analyze API:

f = fopen('music.mp3');
d = fread(f,Inf,'*uint8'); % Read in byte stream of MP3 file
fclose(f);
str = urlreadpost('http://developer.echonest.com/api/upload', ...
{'file',d,'version','3','api_key','API-KEY','wait','Y'});

urlpost checks the type of the value part of each key/value pair, and encodes it as an octet-stream (binary) if it is not
char data. In practice, you should only pass byte data (e.g. the uint8 vector in the example above).

This function is a modified version of the urlread.m function that is part of Matlab R2010a. Also included is the stock urlreadwrite.m helper function since this is used by urlreadpost.m, but won't be found in its private location by default.

인용 양식

Dan Ellis (2024). urlreadpost - url POST method with binary file uploading (https://www.mathworks.com/matlabcentral/fileexchange/27189-urlreadpost-url-post-method-with-binary-file-uploading), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2010a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Web Services에 대해 자세히 알아보기
도움

줌: Steno3D

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.0

I fixed a typo in the example usage fragment (d was referred to as dd).

1.0.0.0