Maurice Raguse
Maurice Raguse

Reputation: 4567

File Upload with Adobe Air

I'm trying to upload a file with Flex to Minus.com

The API Reference explain the upload with this example:

POST /api/v2/folders/0FQHJakL/files?bearer_token=[token] HTTP/1.1 Host: minus.com Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryxECY8varBqIXZW4f Accept-Charset: UTF-8,*;q=0.5

------WebKitFormBoundaryAYAOHDWfizxZB8OE Content-Disposition: form-data; name="file"; filename="test.txt" Content-Type: text/plain

test ------WebKitFormBoundaryAYAOHDWfizxZB8OE Content-Disposition: form-data; name="filename"

test.txt ------WebKitFormBoundaryAYAOHDWfizxZB8OE Content-Disposition: form-data; name="caption"

testfile ------WebKitFormBoundaryAYAOHDWfizxZB8OE--

my AS3 Code is:

var params:URLVariables = new URLVariables();

params.caption = object.offlineFiles[0].name;
params.filename = object.offlineFiles[0].name;

params.bearer_token=appModel.loginData.access_token;

var fr:File = (object.offlineFiles[0] as File);

fr.addEventListener(IOErrorEvent.IO_ERROR,uploadError_Handler);

var request:URLRequest = new URLRequest("http://minus.com/api/v2/folders/......./files");
request.data = params;
request.method = URLRequestMethod.POST;

    fr.upload(request,"file");

but I get an IOErrorEvent...

Upvotes: 0

Views: 1598

Answers (1)

macat
macat

Reputation: 46

Try to send it with "multipart/form-data".

var header:URLRequestHeader = new URLRequestHeader("enctype", "multipart/form-data");
request.requestHeaders.push(header);

Upvotes: 1

Related Questions