我一步一步按照官方 Vimeo 上传文档:Resumable HTTP PUT Uploads
但是在最后一步,删除上传链接时,我总是收到一个 HTTP 500 "Invalid State" 响应,这使所有过程无效。
我已经尝试了一切都没有成功!
相关问题:
为了上传视频,我调整了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)接收上传响应(SUCCESS)
--------- 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) 尝试进行 de 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 ---------