图片上传和错误文件类型
我正在尝试使用 flex 将图像上传到 imageshack,但不断出现
<links>
<error id="wrong_file_type">Wrong file type detected for file IMG_00000009.jpg:application/octet-stream</error>
</links>
我尝试更改 mimetype,但似乎没有什么可以完全做到这一点。
我的方法是这样的:
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");
}
有人可以帮我一下并告诉我我做错了什么吗?我已经浏览了谷歌和这里,但在动作脚本中找不到他的任何解决方法。
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多部分表单上传有多种内容类型。一份用于主要提交,一份用于每个部分。使用 FileReference.upload() 方法时无法设置其中任何一个。遗憾的是,您可能必须使用 imageshack 想要的内容类型构建自己的多部分表单上传。您可以使用 URLLoader 类来完成此操作,但它并不漂亮。
下面是一个可以帮助您入门的课程(也许您无需修改即可使用它):http://code.google.com/p/in-spirit/source/browse/#svn%2Ftrunk%2Fprojects%2FMultipartURLLoader%2Fru%2Finspirit
您也可以要求 imageshack 接受申请/octet-stream 代表各地 Flash 开发人员的图像。
您还可以在 http://bugbase.adobe.com 提交错误/增强请求(该功能记录在以这种方式工作,所以它更多的是一个增强请求)。
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).
好吧,首先,你没有监听任何可能发生的错误(可能是这种情况),如果你想调试,你应该使用 chrome 中的开发人员面板或 firefox 中的 firebug 之类的东西来查看 http要求。
通过快速查看 API,我看到了这个花絮:
我相信您缺少
url
或fileupload
参数才能使其正常工作。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:
I believe you're missing either the
url
orfileupload
parameter for it to work.