Vimeo表单上传不会重定向到提供的URL

时间:2018-04-17 15:17:27

标签: java tomcat vimeo vimeo-api

我正在尝试将视频上传到我的apache tomcat服务器的Vimeo。我正在使用基于表单的上传,我正在提供重定向URL。问题是视频已在Vimeo上正确上传,但我的重定向URL从未被调用过。我正在使用此代码:

        HttpClient httpClient = null;

        RequestConfig.Builder requestBuilder = RequestConfig.custom();
        requestBuilder = requestBuilder.setConnectTimeout(DEFAULT_TIMEOUT);
        requestBuilder = requestBuilder.setConnectionRequestTimeout(DEFAULT_TIMEOUT);

        HttpClientBuilder builder = HttpClientBuilder.create();
        builder.setDefaultRequestConfig(requestBuilder.build());
        httpClient = builder.build();

        HttpPost post = new HttpPost(UPLOAD_POST_URL);

        StringEntity postingString = new StringEntity("{\"upload\" : {\"approach\" : \"post\",\"redirect_url\" : \""+redirectUrl+"\"}}");
        post.setEntity(postingString);
        post.setHeader("Content-type", "application/json");
        post.setHeader("Authorization", "Bearer "+accessToken.trim());
        HttpResponse serverResponse = httpClient.execute(post);

        // get response
        BufferedReader br = new BufferedReader( new InputStreamReader((serverResponse.getEntity().getContent())));

        String output = "";
        String content = "";
        while ((output = br.readLine()) != null) {
            content += output;
        }

        System.out.println("Response 1: "+content);


        // parse the response to see if there was an error
        JsonElement elem = new JsonParser().parse(content);
        JsonObject object = elem.getAsJsonObject();

        if (object.has("error"))
            throw new Exception(object.get("error").getAsString());

        // POST request to upload the video from EFS
        String uploadLink = object.getAsJsonObject("upload").get("upload_link").getAsString();


        post = new HttpPost(uploadLink);

        MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
        entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        entityBuilder.addPart("file_data", new FileBody(new File(videoEFSPath)));
        post.setEntity(entityBuilder.build());

        post.setHeader("Authorization", "Bearer "+accessToken.trim());
        serverResponse = httpClient.execute(post);

        br = new BufferedReader( new InputStreamReader((serverResponse.getEntity().getContent())));

        output = "";
        content = "";
        while ((output = br.readLine()) != null) {
            content += output;
        }

        System.out.println("Response 2: " +content);

        // parse the response to see if there was an error
        elem = new JsonParser().parse(content);
        object = elem.getAsJsonObject();

        if (object.has("error"))
            throw new Exception(object.get("error").getAsString()); 

不会抛出任何异常。我传递的重定向网址是" http:127.0.0.1:8080 / uploadResult"可能是什么问题?

0 个答案:

没有答案