0

I'm trying to upload an image to imageshack using flex, but keep getting

<links>
<error id="wrong_file_type">Wrong file type detected for file IMG_00000009.jpg:application/octet-stream</error>
</links>

I've tried changing the mimetype, but nothing seems to quite do it.

Here's what my method looks like:

protected function onUpload(event:MouseEvent):void
{
    trace('uploading')
    fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, completeHandler);
    var params:URLVariables = new URLVariables();
    params.key = key;
    var request:URLRequest = new URLRequest("http://www.imageshack.us/upload_api.php");
    request.method = URLRequestMethod.POST;
    request.data = params;
    fileRef.upload(request, "fileupload");
}

Could anyone give me a hand here and tell me what i;m doing wrong? I've looked all around google and here, but can't find any kind of workaround for his in actionscript.

Thanks in advance

Marcos Placona
  • 21,468
  • 11
  • 68
  • 93

2 Answers2

1

There are multiple content types for a multi-part form upload. One for the main submission and one for each of the parts. You can't set any of them when using the FileReference.upload() method. Sadly, you may have to build your own multi-part form upload with the content types that imageshack wants. You can do this with the URLLoader class, but it isn't pretty.

Here's a class that should get you started (possibly you can use it without modification): http://code.google.com/p/in-spirit/source/browse/#svn%2Ftrunk%2Fprojects%2FMultipartURLLoader%2Fru%2Finspirit

You might also ask imageshack to accept application/octet-stream for images on behalf of flash developers everywhere.

You can also file a bug/enhancement request at http://bugbase.adobe.com (The feature is documented to work this way, so it's more of an enhancement request).

Joe Ward
  • 749
  • 4
  • 7
  • This is exactly what I ended up doing, so I'll mark this one as the correcdt answer. More details on what I did here: http://stackoverflow.com/questions/7298842/uploading-bytearray-via-urlrequest Thanks anyway – Marcos Placona Sep 11 '11 at 21:38
0

Well, first off, you're not listening for any errors that might be happening (which might be the case) and if you wanted to debug, you should of used something like the developer panel in chrome or firebug in firefox to see the http request.

By doing a quick look at the API, I saw this tidbit:

Supported parameters are:

  • fileupload; (input type="file") - image or video file. Mandatory unless url parameter is specified.
  • frmupload; (input type="file") - video default frame picture. Optional, used only for video upload. When you uploading your video you could supply a default frame that will be displayed when video is stopped. Dimensions of this image should be the same as video file's ones to avoid artefacts on screen.
  • url; This parameter indicates that transload method is used instead of upload optsize; resize options for image in form WxH if image is uploaded/transloaded. No impact on video uploads.
  • rembar; Developer could tell to ImageShack to leave/remove information bar on thumbnail image generated by ImageShack . If you've supplied this parameter as yes or as 1 then generated thumbmail will have no information bar. No impact on video uploads tags; A comma-separated list of tags to add to your video/image. E.g. family,picture. Optional
  • public; Public/private marker of your video/picture. yes means public (default), no means private. Optional
  • cookie; Registration code, optional.
  • a_username; Username, optional.
  • a_password; Password, optional.
  • key; Your DeveloperKey. Mandatory.

I believe you're missing either the url or fileupload parameter for it to work.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • No errors are happening, and the xml is being returned by imageshack, Also, I an passing the fileupload as you can see on my code snippet: fileRef.upload(request, "fileupload"); – Marcos Placona Aug 29 '11 at 15:42
  • Ah, I think it's sending the wrong content-type in the post. By default FileReference sends `Content-Type: application/octet-stream`. You'll need to change that to whatever ImageShack needs (an image maybe?). – J_A_X Aug 29 '11 at 23:53
  • And that's my problem, I can't seem to be able to change that. Could you tell me how to do it? Thanks – Marcos Placona Aug 30 '11 at 06:34
  • That's weird because this content type should work on imageshack. Sadly, the api says `For FileReference.upload(), the Content-Type of the request is set automatically to multipart/form-data, and the value of the contentType property is ignored.`. Your only choice would be to use HTTPService.send with all your parameters and a bytearray of the image. – J_A_X Aug 30 '11 at 07:20
  • Don't think you can accomplish this with HTTPService. Would you be able to give me an example? – Marcos Placona Aug 30 '11 at 20:11