Vimeo上传API - 尝试删除票证时出现“无效状态”错误

时间:2016-08-05 02:39:47

标签: android vimeo vimeo-api vimeo-android

我一步一步地遵循了官方Vimeo上传文档:Resumable HTTP PUT Uploads

但是在最后一步中,删除上传链接我总是收到HTTP 500“无效状态”回复,这会使所有进程失效。

我尝试过一切都没有成功!

  

相关问题:

     

"Invalid State" after Vimeo API delete

     

Vimeo Forum: Invalid state during upload of video

要上传视频,我修改了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 ---------

1 个答案:

答案 0 :(得分:3)

基于this comment,我解决了将上传Retrofit方法更改为不使用Multipart的问题!

现在上传到Vimeo已经完成,最后成功删除了上传票!

旧的:

@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);