Though by building new put request and and setting the necessary headers
values i m still getting the same Error as i have described
previously.for more information please go through my code for uploading
document as following:
static void uploadDocs() {
File sdcard = Environment.
getExternalStorageDirectory();
File file = new File(sdcard.getAbsolutePath() + "/download/iridium.pdf");
InputStream stream = null;
HttpRequest request;
try {
stream = new FileInputStream(file);
InputStreamContent streamContent = new InputStreamContent(
"application/pdf", stream);
request = rf.buildPostRequest(DocsUrl.forCreate(), streamContent);
GoogleHeaders headers = (GoogleHeaders) request.getHeaders();
headers.setSlugFromFileName("iridium.pdf");
headers.set("X-Upload-Content-Length", file.length());
headers.set("X-Upload-Content-Type", "application/pdf");
headers.setContentType("application/pdf");
request.setHeaders(headers);
HttpResponse response = request.execute();
String upUrl = response.getHeaders().getLocation();
headers=null;
response = null;
long i = 0, j = 0;
while (i < file.length()) {
j = i + 524287;
DocsUrl objDocsUrl = DocsUrl.forUpload(upUrl);
HttpRequest rptrequest = rf.buildPutRequest(objDocsUrl,
streamContent);
headers = (GoogleHeaders)rptrequest.getHeaders();
if (j > file.length()) {
headers.setRange(
"bytes " + String.valueOf(i) + "-"
+ String.valueOf(file.length()) + "/"
+ String.valueOf(file.length()));
} else {
headers.setRange(
"bytes " + String.valueOf(i) + "-"
+ String.valueOf(j) + "/"
+ String.valueOf(file.length()));
i = j + 1;
}
headers.setSlugFromFileName("iridium.pdf");
headers.set("X-Upload-Content-Type", "application/pdf");
headers.setContentType("application/pdf");
rptrequest.setHeaders(headers);
response = rptrequest.execute();
upUrl = response.getHeaders().getLocation();
rptrequest = null;
headers = null;
response = null;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();