问题描述
我逐步遵循了官方Vimeo上传文档:可恢复的HTTP PUT上传
I followed step by step of the oficial Vimeo Upload doc: Resumable HTTP PUT Uploads
但是在最后一步中,删除上传链接,我始终会收到HTTP 500无效状态"响应,这会使所有过程无效.
But in the last step, delete the upload link, I always receive a HTTP 500 "Invalid State" response, what invalidates all the process.
我尝试了一切都没有成功!
I have tried everything without success!
要上传视频,我改编了 vimeo-networking -java API.
To upload the video, I adapted the vimeo-networking-java API.
上面的主要变化:
在VimeoService.java中
@Multipart
@Headers("Content-Type: video/mp4")
@PUT
Call<Object> UPLOAD(@Header("Authorization") String authHeader,
@Url String uri,
@Header("Content-Length") String contentLenght,
@Part("file") RequestBody body);
@PUT
Call<Object> CHECK_UPLOAD(@Header("Authorization") String authHeader,
@Url String uri,
@Header("Content-Length") String contentLenght,
@Header("Content-Range") String contentRange);
在VimeoClient.java中
@Nullable
public Call<Object> upload(String uri, long contentLenght, byte[] body, VimeoCallback<Object> callback) {
if (callback == null) {
throw new AssertionError("Callback cannot be null");
}
if (uri == null) {
callback.failure(new VimeoError("uri cannot be empty!"));
return null;
}
MediaType MEDIA_TYPE = MediaType.parse("video/mp4");
RequestBody requestBody = RequestBody.create(MEDIA_TYPE, body);
Call<Object> call = this.vimeoService.UPLOAD(
getAuthHeader(),
uri,
Long.toString(contentLenght),
requestBody);
callback.setCall(call);
call.enqueue(callback);
return call;
}
@Nullable
public Call<Object> checkUpload(String uri, VimeoCallback<Object> callback) {
if (callback == null) {
throw new AssertionError("Callback cannot be null");
}
if (uri == null) {
callback.failure(new VimeoError("uri cannot be empty!"));
return null;
}
Call<Object> call = this.vimeoService.CHECK_UPLOAD(getAuthHeader(), uri, Long.toString(0), "bytes */*");
callback.setCall(call);
call.enqueue(callback);
return call;
}
完整的过程日志(请求和响应)
1)获取上传票证
--------- REQUEST ---------
METHOD: POST
ENDPOINT: https://api.vimeo.com/me/videos
--------- REQUEST HEADERS ---------
AUTHORIZATION: Bearer b750c6967df2a9ac068d5277f0985b5a
--------- REQUEST HEADERS END ---------
QUERY: null
--------- REQUEST BODY ---------
{
"type": "streaming"
}
--------- REQUEST BODY END ---------
--------- REQUEST END ---------
--------- RESPONSE ---------
ENDPOINT: https://api.vimeo.com/me/videos
STATUS CODE: 201
REQUEST TIME: 11307,4ms
--------- RESPONSE HEADERS ---------
ACCEPT-RANGES: bytes
CACHE-CONTROL: public
CONNECTION: keep-alive
CONTENT-TYPE: application/vnd.vimeo.uploadticket+json
DATE: Fri, 05 Aug 2016 02:12:20 GMT
EXPIRES: Mon, 03 Aug 2026 02:12:08 GMT
FASTLY-DEBUG-DIGEST: 671da88c3ec81bbd101a0bb851a90184165c1f4f3599229b0eb782c555e41ae7
OKHTTP-RECEIVED-MILLIS: 1470363157021
OKHTTP-SENT-MILLIS: 1470363145728
SERVER: nginx
STRICT-TRANSPORT-SECURITY: max-age=15120000; includeSubDomains; preload
VARY: Accept,Vimeo-Client-Id,Accept-Encoding
VIA: 1.1 varnish
X-CACHE: MISS, MISS
X-CACHE-HITS: 0, 0
X-RATELIMIT-LIMIT: 100
X-RATELIMIT-REMAINING: 98
X-RATELIMIT-RESET: 2016-08-05T02:27:09+00:00
X-SERVED-BY: cache-iad2125-IAD, cache-gru7124-GRU
X-TIMER: S1470363128.926327,VS0,VE11196
--------- RESPONSE HEADERS END ---------
--------- RESPONSE BODY ---------
{
"uri": "/users/user54333244/tickets/6d81c45bef8c85b20ab4ffe268c871f7",
"ticket_id": "6d81c45bef8c85b20ab4ffe268c871f7",
"user": {...},
"upload_link": "http://1511923119.cloud.vimeo.com/upload?ticket_id\u003d6d81c45bef8c85b20ab4ffe268c871f7\u0026video_file_id\u003d577958619\u0026signature\u003d662f6286a14464c6347648e0ce642523\u0026v6\u003d1",
"upload_link_secure": "https://1511923119.cloud.vimeo.com/upload?ticket_id\u003d6d81c45bef8c85b20ab4ffe268c871f7\u0026video_file_id\u003d577958619\u0026signature\u003d662f6286a14464c6347648e0ce642523\u0026v6\u003d1",
"complete_uri": "/users/54333244/tickets/6d81c45bef8c85b20ab4ffe268c871f7?video_file_id\u003d577958619\u0026upgrade\u003dtrue\u0026signature\u003d662f6286a14464c6347648e0ce642523"
}
--------- RESPONSE BODY END ---------
--------- RESPONSE END ---------
2)发出上传请求
--------- REQUEST ---------
METHOD: PUT
ENDPOINT: https://1511923119.cloud.vimeo.com/upload?ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
--------- REQUEST HEADERS ---------
AUTHORIZATION: Bearer b750c6967df2a9ac068d5277f0985b5a
CONTENT-LENGTH: 2061435
--------- REQUEST HEADERS END ---------
QUERY: ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
--------- REQUEST BODY ---------
Request body is to large to print
--------- REQUEST BODY END ---------
--------- REQUEST END ---------
3)-首次验证上传-不完整(1202177/2061435)
--------- REQUEST ---------
METHOD: PUT
ENDPOINT: https://1511923119.cloud.vimeo.com/upload?ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
--------- REQUEST HEADERS ---------
AUTHORIZATION: Bearer b750c6967df2a9ac068d5277f0985b5a
CONTENT-LENGTH: 0
CONTENT-RANGE: bytes */*
--------- REQUEST HEADERS END ---------
QUERY: ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
--------- REQUEST BODY ---------
--------- REQUEST BODY END ---------
--------- REQUEST END ---------
--------- RESPONSE ---------
ENDPOINT: https://1511923119.cloud.vimeo.com/upload?ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
STATUS CODE: 308
REQUEST TIME: 2292,3ms
--------- RESPONSE HEADERS ---------
ACCESS-CONTROL-ALLOW-HEADERS: Content-Type, Content-Range, X-Requested-With
ACCESS-CONTROL-ALLOW-METHODS: POST, PUT, GET, OPTIONS
ACCESS-CONTROL-ALLOW-ORIGIN: *
ACCESS-CONTROL-EXPOSE-HEADERS: Range
CACHE-CONTROL: public
CONNECTION: close
CONTENT-LENGTH: 0
CONTENT-TYPE: text/plain
DATE: Fri, 05 Aug 2016 02:10:45 GMT
OKHTTP-RECEIVED-MILLIS: 1470363169855
OKHTTP-SENT-MILLIS: 1470363168232
RANGE: bytes=0-1202177 <<========================================
SERVER: Vimeo/1.0
TIMING-ALLOW-ORIGIN: *
X-BACKEND-SERVER: kopiluwak
X-REQUESTED-WITH: XMLHttpRequest
--------- RESPONSE HEADERS END ---------
--------- RESPONSE BODY ---------
--------- RESPONSE BODY END ---------
--------- RESPONSE END ---------
4)接收上传响应(成功)
--------- RESPONSE ---------
ENDPOINT: https://1511923119.cloud.vimeo.com/upload?ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
STATUS CODE: 200
REQUEST TIME: 5550,2ms
--------- RESPONSE HEADERS ---------
ACCESS-CONTROL-ALLOW-HEADERS: Content-Type, Content-Range, X-Requested-With
ACCESS-CONTROL-ALLOW-METHODS: POST, PUT, GET, OPTIONS
ACCESS-CONTROL-ALLOW-ORIGIN: *
ACCESS-CONTROL-EXPOSE-HEADERS: Range
CACHE-CONTROL: public
CONNECTION: close
CONTENT-LENGTH: 0
CONTENT-TYPE: text/plain
DATE: Fri, 05 Aug 2016 02:10:47 GMT
OKHTTP-RECEIVED-MILLIS: 1470363171089
OKHTTP-SENT-MILLIS: 1470363166094
SERVER: Vimeo/1.0
TIMING-ALLOW-ORIGIN: *
X-BACKEND-SERVER: kopiluwak
X-REQUESTED-WITH: XMLHttpRequest
--------- RESPONSE HEADERS END ---------
--------- RESPONSE BODY ---------
--------- RESPONSE BODY END ---------
--------- RESPONSE END ---------
5)-再次验证上传-已完成(2061651/2061651)
--------- REQUEST ---------
METHOD: PUT
ENDPOINT: https://1511923119.cloud.vimeo.com/upload?ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
--------- REQUEST HEADERS ---------
AUTHORIZATION: Bearer b750c6967df2a9ac068d5277f0985b5a
CONTENT-LENGTH: 0
CONTENT-RANGE: bytes */*
--------- REQUEST HEADERS END ---------
QUERY: ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
--------- REQUEST BODY ---------
--------- REQUEST BODY END ---------
--------- REQUEST END ---------
--------- RESPONSE ---------
ENDPOINT: https://1511923119.cloud.vimeo.com/upload?ticket_id=6d81c45bef8c85b20ab4ffe268c871f7&video_file_id=577958619&signature=662f6286a14464c6347648e0ce642523&v6=1
STATUS CODE: 308
REQUEST TIME: 185,4ms
--------- RESPONSE HEADERS ---------
ACCESS-CONTROL-ALLOW-HEADERS: Content-Type, Content-Range, X-Requested-With
ACCESS-CONTROL-ALLOW-METHODS: POST, PUT, GET, OPTIONS
ACCESS-CONTROL-ALLOW-ORIGIN: *
ACCESS-CONTROL-EXPOSE-HEADERS: Range
CACHE-CONTROL: public
CONNECTION: close
CONTENT-LENGTH: 0
CONTENT-TYPE: text/plain
DATE: Fri, 05 Aug 2016 02:10:48 GMT
OKHTTP-RECEIVED-MILLIS: 1470363172083
OKHTTP-SENT-MILLIS: 1470363171995
RANGE: bytes=0-2061651 <<========================================
SERVER: Vimeo/1.0
TIMING-ALLOW-ORIGIN: *
X-BACKEND-SERVER: kopiluwak
X-REQUESTED-WITH: XMLHttpRequest
--------- RESPONSE HEADERS END ---------
--------- RESPONSE BODY ---------
--------- RESPONSE BODY END ---------
--------- RESPONSE END ---------
6)尝试进行DELETE调用-发生无效状态"错误的地方.
--------- REQUEST ---------
METHOD: DELETE
ENDPOINT: https://api.vimeo.com/users/54333244/tickets/6d81c45bef8c85b20ab4ffe268c871f7?video_file_id=577958619&upgrade=true&signature=662f6286a14464c6347648e0ce642523
--------- REQUEST HEADERS ---------
AUTHORIZATION: Bearer b750c6967df2a9ac068d5277f0985b5a
--------- REQUEST HEADERS END ---------
--------- REQUEST END ---------
--------- RESPONSE ---------
ENDPOINT: https://api.vimeo.com/users/54333244/tickets/6d81c45bef8c85b20ab4ffe268c871f7?video_file_id=577958619&upgrade=true&signature=662f6286a14464c6347648e0ce642523
STATUS CODE: 500
REQUEST TIME: 4959,4ms
--------- RESPONSE HEADERS ---------
ACCEPT-RANGES: bytes
CACHE-CONTROL: public
CONNECTION: keep-alive
CONTENT-TYPE: application/vnd.vimeo.error+json
DATE: Fri, 05 Aug 2016 02:12:40 GMT
EXPIRES: Mon, 03 Aug 2026 02:12:35 GMT
FASTLY-DEBUG-DIGEST: 8ed132ece40c90a7e97e1901d8ab96bbe5eef838cc09da5736ea3b2f25dda430
OKHTTP-RECEIVED-MILLIS: 1470363177088
OKHTTP-SENT-MILLIS: 1470363172147
SERVER: nginx
STRICT-TRANSPORT-SECURITY: max-age=15120000; includeSubDomains; preload
VARY: Accept,Vimeo-Client-Id,Accept-Encoding
VIA: 1.1 varnish
X-CACHE: MISS, MISS
X-CACHE-HITS: 0, 0
X-RATELIMIT-LIMIT: 250
X-RATELIMIT-REMAINING: 244
X-RATELIMIT-RESET: 2016-08-05T02:27:35+00:00
X-SERVED-BY: cache-iad2134-IAD, cache-gru7124-GRU
X-TIMER: S1470363155.338298,VS0,VE4824
--------- RESPONSE HEADERS END ---------
--------- RESPONSE BODY ---------
{
"error": "Invalid state" <<========================================
}
--------- RESPONSE BODY END ---------
--------- RESPONSE END ---------
推荐答案
基于此评论,我解决了将上载Retrofit方法更改为不使用Multipart的问题!
Based on this comment, I solved the problem changing the upload Retrofit method to not use Multipart!
现在到Vimeo的上传已完成,最后成功删除了上传票证!
Now the upload to Vimeo is completed, successfully deleting the upload ticket at the end!
旧版本:
@Multipart
@Headers("Content-Type: video/mp4")
@PUT
Call<Object> UPLOAD(@Header("Authorization") String authHeader,
@Url String uri,
@Header("Content-Length") String contentLenght,
@Part("file") RequestBody body);
新的一个:
@Headers("Content-Type: video/mp4")
@PUT
Call<Object> UPLOAD(@Header("Authorization") String authHeader,
@Url String uri,
@Header("Content-Length") String contentLenght,
@Body RequestBody body);
这篇关于Vimeo Upload API-“无效状态"尝试删除故障单时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!