-1

As of now, im using the signed url technique to get the files from GCS

BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, gcsFolderPrefix + fullFileName)).build();
URL url = storage.signUrl(blobInfo, 15, TimeUnit.MINUTES,Storage.SignUrlOption.withV4Signature());

After hitting the generated signed url in the browser , its getting downloaded but I need to open the file,I tried by adding the response headers also like below:

response.addHeader(HttpHeaders.CONTENT_TYPE, "multipart/form-data");
response.addHeader(HttpHeaders.CONTENT_DISPOSITION,"inline;filename=" + fileId.toString()+".pdf");
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    Does this answer your question? [How do I force files to open in the browser instead of downloading (PDF)?](https://stackoverflow.com/questions/6293893/how-do-i-force-files-to-open-in-the-browser-instead-of-downloading-pdf) – rkosegi Nov 24 '20 at 07:11
  • No, after the hitting the signed url in the browser its getting downloaded directly instead of opening – Ajith Kumar Nov 24 '20 at 07:29

1 Answers1

1

You need to update the metadata of your blob in GCS before generating the SignedUrl

BlobInfo blobinfo = BlobInfo.newBuilder(BlobId.of(bucketName, gcsFolderPrefix + fullFileName))
//Add the correct content type
.setContentType("application/pdf")
.build();

// Update the Blob
storage.update(blobinfo);

URL url = storage.signUrl(blobInfo, 15, TimeUnit.MINUTES,Storage.SignUrlOption.withV4Signature());

rkosegi
  • 14,165
  • 5
  • 50
  • 83
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76