图片上传和错误文件类型

发布于 2024-12-02 01:21:43 字数 811 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉世弥音 2024-12-09 01:21:43

多部分表单上传有多种内容类型。一份用于主要提交,一份用于每个部分。使用 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).

捂风挽笑 2024-12-09 01:21:43

好吧,首先,你没有监听任何可能发生的错误(可能是这种情况),如果你想调试,你应该使用 chrome 中的开发人员面板或 firefox 中的 firebug 之类的东西来查看 http要求。

通过快速查看 API,我看到了这个花絮:

支持的参数有:

  • 文件上传; (输入类型=“文件”) - 图像或视频文件。强制的
    除非指定了 url 参数。
  • frm上传; (input type="file") - 视频默认帧图片。
    可选,仅用于视频上传。当您上传视频时
    您可以提供一个默认帧,该帧将在视频播放时显示
    停了下来。该图像的尺寸应与视频文件的尺寸相同
    以避免屏幕上出现伪影。
  • 网址;该参数表示使用transload方式代替
    上传优化大小;如果图像是,则以宽x高的形式调整图像的大小选项
    上传/转发。对视频上传没有影响。
  • 伦巴尔;开发人员可以告诉 ImageShack 离开/删除
    ImageShack 生成的缩略图上的信息栏。如果你有
    将此参数提供为 yes 或 1,然后生成的缩略图将
    没有信息栏。对视频上传标签没有影响;一个
    要添加到视频/图像的以逗号分隔的标签列表。例如
    家庭, 图片.可选
  • 公开;您的视频/图片的公共/私人标记。是的意思是
    public(默认),no 表示私有。可选
  • cookie;注册码,可选。
  • a_用户名;用户名,可选。
  • 密码;密码,可选。
  • 键;您的开发者密钥。强制。

我相信您缺少 urlfileupload 参数才能使其正常工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文