开发者社区 问答 正文

apicloud 的api.ajax上传文件到oss失败



把oss提供的例子放到app中,plupload的上传是没问题的;


var uploader = new plupload.Uploader({
        runtimes : 'html5,html4',
        browse_button : 'selectfiles',
       //runtimes : 'flash',
        container: document.getElementById('container'),
        //flash_swf_url : 'lib/plupload-2.1.2/js/Moxie.swf',
        //silverlight_xap_url : 'lib/plupload-2.1.2/js/Moxie.xap',
       url : host,
        multipart_params: {
                'Filename': '${filename}',
                'key' : '${filename}',
                'policy': policyBase64,
                 'OSSAccessKeyId': accessid,
                  'success_action_status' : '200', //让服务端返回200,不然,默认会返回204
                'signature': signature,
        },


仿照上面的请求信息,用api.ajax去请求就返回400的错误,谁能帮忙看看?
{"statusCode":400,"body":"服务器错误","msg":"服务器错误","code":0}


        api.ajax({
                url :  host
                method : 'post',
                timeout : 30,
                dataType : 'json',
                returnAll : true,
                
                //async: false,
                //cache: false,
                //processData: false,
                //contentType: false,
                data : {
                        values: {
                                'Filename': '${filename}',
                                'key' : '${filename}',
                                'policy': policyBase64,
                                'OSSAccessKeyId': accessid,
                                'success_action_status' : '200',
                                'signature': signature
                        },
                        
                        files: {
                                'file': filepath
                        }
                }
        }, function(ret, err) {


失败时的请求信息(api.ajax的请求),没看出和正确时的有什么不一样的,参数都一致的;
POST /  HTTP/1.1
Accept-Encoding: gzip, deflate
User-Agent: APICloud/1.0 (Linux; U; Android 4.4.2; H60-L01)
Charset: UTF-8
Connection: Keep-Alive
Accept: */*
Content-Type: multipart/form-data; boundary=tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Host: xxx.xxx.xxx.xxx


Content-Length: 36331


--tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Content-Disposition: form-data; name="success_action_status"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


200
--tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Content-Disposition: form-data; name="OSSAccessKeyId"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


xxxxxxxxxxxxxxxxxx
--tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Content-Disposition: form-data; name="policy"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Content-Disposition: form-data; name="Signature"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Content-Disposition: form-data; name="key"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


123
--tHI-hnPNf1cBiD_KJ9SMO_EPL_bFblr8hzQxE8NH
Content-Disposition: form-data; name="file"; filename="b1009832-ab8b-cc0c-f6de-e292d07d5366.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary


好使时的请求内容(uploader对象上传时的请求):
POST / HTTP/1.1
Host: xxx.xxx.xxx.xxx
Connection: keep-alive
Content-Length: 2771785
Origin: file://
x-wap-profile: xxxx
User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; H60-L01 Build/HDH60-L01) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryaITtOL7KsYZAHvUK
Accept: */*
Accept-Encoding: gzip,deflate
Accept-Language: zh-CN,en-US;q=0.8
X-Requested-With: com.apicloud.apploader


------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="name"


p-f80768fc.jpg
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="Filename"


${filename}
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="key"


zuohaoshi/10002/${filename}
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="policy"


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="OSSAccessKeyId"


xxxxxxxxxxxxxxxxxx
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="success_action_status"


200
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="signature"


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
------WebKitFormBoundaryaITtOL7KsYZAHvUK
Content-Disposition: form-data; name="file"; filename="p-f80768fc.jpg"
Content-Type: image/jpeg

展开
收起
jincm 2016-01-17 19:01:07 13631 分享 版权
2 条回答
写回答
取消 提交回答
  • Reapicloud 的api.ajax上传文件到oss失败
    同求!!!怎么没有人来帮忙?

    -------------------------

    回 3楼shinenuaa的帖子
    跟楼主的一模一样

    -------------------------

    回 3楼shinenuaa的帖子
    plupload上传时,执行了一次OPTIONS请求,而apicloud api.ajax 没有这一步,会不会是这个的问题?

    bbs.aliyun.com/read/250407.html
    2016-01-26 16:30:48
    赞同 展开评论
  • 能不能提供一下OSS返回的Body内容,最好有请求的RequestID

    -------------------------

    回 2楼(pxz252) 的帖子
    把出错的信息,贴一下。
    2016-01-18 10:08:39
    赞同 展开评论