Vimeo Upload API - "Invalid state" error trying to delete the ticket
Asked Answered
S

1

1

I followed step by step of the oficial Vimeo Upload doc: Resumable HTTP PUT Uploads

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!

Related questions:

"Invalid State" after Vimeo API delete

Vimeo Forum: Invalid state during upload of video


To upload the video, I adapted the vimeo-networking-java API.

Main changes above:

In the 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);

In the 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;
}

THE COMPLETE PROCESS LOG (REQUESTS AND RESPONSES)

1) Getting an upload ticket

--------- 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) Making the upload request

--------- 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) Verifying the upload - first time - incomplete (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) Receveing the upload response (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) Verifying the upload - second time - COMPLETED (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) Trying to make de DELETE call - where the "Invalid State" error happens.

--------- 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 ---------
Stepmother answered 5/8, 2016 at 2:39 Comment(0)
S
3

Based on this comment, I solved the problem changing the upload Retrofit method to not use Multipart!

Now the upload to Vimeo is completed, successfully deleting the upload ticket at the end!

Old one:

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

New one:

@Headers("Content-Type: video/mp4")
@PUT
Call<Object> UPLOAD(@Header("Authorization") String authHeader,
                    @Url String uri,
                    @Header("Content-Length") String contentLenght,
                    @Body RequestBody body);
Stepmother answered 5/8, 2016 at 15:42 Comment(1)
Awesome work! We at Vimeo have held off releasing an upload library since the app uses 2-step upload as opposed to this 4-step process, and it is still in beta (and the Android app didn't exist when only 4-step was around). I have seen a lot of posts on SO about wanting support for upload. Would you want to open a PR against vimeo-networking? This way others can take advantage of your findings until 2-step is released to the public.Commuter

© 2022 - 2024 — McMap. All rights reserved.