|
17 | 17 | import com.google.api.client.googleapis.GoogleHeaders; |
18 | 18 | import com.google.api.client.googleapis.MethodOverride; |
19 | 19 | import com.google.api.client.http.AbstractInputStreamContent; |
20 | | -import com.google.api.client.http.ByteArrayContent; |
| 20 | +import com.google.api.client.http.EmptyContent; |
21 | 21 | import com.google.api.client.http.GenericUrl; |
22 | 22 | import com.google.api.client.http.HttpContent; |
23 | 23 | import com.google.api.client.http.HttpMethod; |
@@ -268,7 +268,6 @@ public HttpResponse upload(GenericUrl initiationRequestUrl) throws IOException { |
268 | 268 | while (true) { |
269 | 269 | currentRequest = requestFactory.buildPutRequest(uploadUrl, null); |
270 | 270 | new MethodOverride().intercept(currentRequest); // needed for PUT |
271 | | - currentRequest.setAllowEmptyContent(false); |
272 | 271 | setContentAndHeadersOnCurrentRequest(bytesUploaded); |
273 | 272 | if (backOffPolicyEnabled) { |
274 | 273 | // Set MediaExponentialBackOffPolicy as the BackOffPolicy of the HTTP Request which will |
@@ -326,13 +325,13 @@ private HttpResponse executeUploadInitiation(GenericUrl initiationRequestUrl) th |
326 | 325 | updateStateAndNotifyListener(UploadState.INITIATION_STARTED); |
327 | 326 |
|
328 | 327 | initiationRequestUrl.put("uploadType", "resumable"); |
| 328 | + HttpContent content = metadata == null ? new EmptyContent() : metadata; |
329 | 329 | HttpRequest request = |
330 | | - requestFactory.buildRequest(initiationMethod, initiationRequestUrl, metadata); |
| 330 | + requestFactory.buildRequest(initiationMethod, initiationRequestUrl, content); |
331 | 331 | addMethodOverride(request); |
332 | 332 | initiationHeaders.setUploadContentType(mediaContent.getType()); |
333 | 333 | initiationHeaders.setUploadContentLength(getMediaContentLength()); |
334 | 334 | request.setHeaders(initiationHeaders); |
335 | | - request.setAllowEmptyContent(false); |
336 | 335 | request.setRetryOnExecuteIOException(true); |
337 | 336 | request.setEnableGZipContent(true); |
338 | 337 | HttpResponse response = request.execute(); |
@@ -400,9 +399,6 @@ public void serverErrorCallback() throws IOException { |
400 | 399 | // Query the current status of the upload by issuing an empty POST request on the upload URI. |
401 | 400 | HttpRequest request = requestFactory.buildPutRequest(currentRequest.getUrl(), null); |
402 | 401 | new MethodOverride().intercept(request); // needed for PUT |
403 | | - // The resumable media upload protocol requires Content-Length to be 0. |
404 | | - request.setAllowEmptyContent(true); |
405 | | - request.setContent(new ByteArrayContent(null, new byte[0])); |
406 | 402 |
|
407 | 403 | request.getHeaders().setContentRange("bytes */" + getMediaContentLength()); |
408 | 404 | request.setThrowExceptionOnExecuteError(false); |
|
0 commit comments