0

I'm able to send the file in GCS Bucket as an attachment using Sendgrid API. However, I'm not able to do the same with the file present in the local system.

The code I've used for GCS file transfer is

StorageOptions options = StorageOptions.newBuilder()
            .setProjectId(PROJECT_ID)
            .setCredentials(GoogleCredentials.fromStream(
                    new FileInputStream(PATH_TO_JSON_KEY))).build();
Storage storage = options.getService(); 
Blob blob = storage.get(BUCKET_NAME, OBJECT_NAME);

Using the above code I am able to read the content of the data, but how can we use that function if our file is in local system rather than GCS Bucket?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Does this answer your question? [SendGrid emailing API , send email attachment](https://stackoverflow.com/questions/38599079/sendgrid-emailing-api-send-email-attachment) – Ziumin Jan 27 '20 at 11:51
  • I'm getting the below error when i use the code of the 1st answer present over there...**The method getBytes(Path) is undefined for the type Path**...the error is in the line ** byte[] attachmentContentBytes = Files.readAllBytes(file); **..is there anything library to be imported to sole this issue. – Chakkirala Chaitanya Jan 27 '20 at 12:21
  • even i've used the function 'readAllBytes()' though i'm getting the same. – Chakkirala Chaitanya Jan 27 '20 at 12:21

0 Answers0