:
为分割的第一段确为 Access Key 的 base64 编码;第三段确为 put policy 的 json 的 base64 编码(如果这个都能错就是你们 Ruby SDK 的问题)def upload_token
put_policy = Qiniu::Auth::PutPolicy.new 'xxxxxx'
put_policy.fsize_limit = "20971520"
put_policy.mime_limit = "image/*;video/*"
token = Qiniu::Auth.generate_uptoken(put_policy)
render json: {token: token}, status: :created
end
@Multipart
@POST("/")
void upload(@Part("file") CountingTypedStream stream,
@Part("token") TypedString token,
Callback<UploadResult> callback);
产生的请求体如下(省略 file part。SF 你又擅自着色我的代码了!):
--667fdbb3-301f-4f25-ab8d-acc80ca14192
Content-Disposition: form-data; name="token"
Content-Type: text/plain; charset=UTF-8
Content-Length: 202
Content-Transfer-Encoding: binary
Y0这是我的AK无误t5:1o1Ic这里也没问题42UVEo=:eyJzY这一串也没问题KiJ9
--667fdbb3-301f-4f25-ab8d-acc80ca14192--
返回给我的东西(取自日志):
07-24 22:59:43.266 D/Retrofit﹕ <--- HTTP 401 http://upload.qiniu.com/ (13126ms)
07-24 22:59:43.266 D/Retrofit﹕ : HTTP/1.1 401 Unauthorized
07-24 22:59:43.266 D/Retrofit﹕ Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size
07-24 22:59:43.266 D/Retrofit﹕ Access-Control-Allow-Methods: OPTIONS, HEAD, POST
07-24 22:59:43.266 D/Retrofit﹕ Access-Control-Allow-Origin: *
07-24 22:59:43.266 D/Retrofit﹕ Cache-Control: no-store, no-cache, must-revalidate
07-24 22:59:43.266 D/Retrofit﹕ Connection: close
07-24 22:59:43.266 D/Retrofit﹕ Content-Length: 39
07-24 22:59:43.266 D/Retrofit﹕ Content-Type: application/json
07-24 22:59:43.266 D/Retrofit﹕ Date: Thu, 24 Jul 2014 14:59:43 GMT
07-24 22:59:43.266 D/Retrofit﹕ Pragma: no-cache
07-24 22:59:43.266 D/Retrofit﹕ Server: nginx/1.4.4
07-24 22:59:43.266 D/Retrofit﹕ X-Android-Received-Millis: 1406213983252
07-24 22:59:43.266 D/Retrofit﹕ X-Android-Response-Source: NETWORK 401
07-24 22:59:43.266 D/Retrofit﹕ X-Android-Selected-Transport: http/1.1
07-24 22:59:43.266 D/Retrofit﹕ X-Android-Sent-Millis: 1406213970562
07-24 22:59:43.266 D/Retrofit﹕ X-Content-Type-Options: nosniff
07-24 22:59:43.266 D/Retrofit﹕ X-Log: UP:17/401
07-24 22:59:43.266 D/Retrofit﹕ X-Reqid: JUAAAFZBtNkq4IMT
07-24 22:59:43.266 D/Retrofit﹕ X-Via: 1.1 gzqxg204:1 (Cdn Cache Server V2.0)
07-24 22:59:43.274 D/Retrofit﹕ {"error":"invalid put policy encoding"}
07-24 22:59:43.274 D/Retrofit﹕ <--- END HTTP (39-byte body)
--4da8f9b3-4e83-483b-b206-96faf1c4574d
Content-Disposition: form-data; name="token"
我是PutPolicy肯定没问题啦啦啦啦啦啦
--4da8f9b3-4e83-483b-b206-96faf1c4574d
Content-Disposition: form-data; name="file"; filename="stream_file"
Content-Type: application/octet-stream
文件内容
--4da8f9b3-4e83-483b-b206-96faf1c4574d--
完全按照 http://developer.qiniu.com/docs/v6/api/reference/up/upload.html 的格式构建,Header 不多不少。
学习是最好的投资!