JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Attach file from Predefined Files Collection using SendGrid

Hi there,

I have Sendgrid working successfully, but I would like to attach a file that is stored in the Predefined Files Collection. There will be 3 file types that I want to attach (not all in the one email), these are gpx (GPS exchange format), pdf and image. I need to get the gpx file working first.

Can you please provide some guidance on how this can be done?

Can I somehow use a link to the object in the files collection in the SendGrid Api?

Will the same technique work for all file formats?

Any advice would be greatly appreciated.

Thanks
James

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Attach file from Predefined Files Collection using SendGrid

Hello Jimmy,

Please check this doc, hope it will be useful for you:
http://blog.bismallion.com/appery-sen...

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Attach file from Predefined Files Collection using SendGrid

Hi Evgene,

I have previously read that document but I wasn't sure on how to actually read / download the file in the first instance as this is not described. It just says "read file content first".

How do I download the file?

Then, how do I read the file?

Thanks
James

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Attach file from Predefined Files Collection using SendGrid

Hi again,

I have managed to upload a file as per the link you provided. Which is great!

However I would like to use the text that is in a file in my predefined collection (its the gpx file which is xlm) not the dummy text "Hi".

Any advice on how to get the file and read it?

var content = "Hi";

alert(content);
// Read file content first
var blob = new Blob([content], { type: "image/jpeg"});

var fileName = 'ZZZ.txt';
// Read file name first
formData.append("files[" + fileName + "]", blob);
alert(formData);

var request = new XMLHttpRequest();

request.withCredentials = true;

request.open("POST", "https://api.sendgrid.com/api/mail.sen...");
request.setRequestHeader("Access-Control-Allow-Origin", "*");
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.send(formData);

request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
alert('E-mail sent successfully');
// Apperyio('status_label').text('E-mail sent');
// setTimeout(function(){Apperyio('status_label').text('Ready');},2000);
}
};

Code: Select all

         settings.success({}); 
         alert("settingcomplete"); 
     } 
     settings.complete('success'); 
 } 

});

JimmyH
Posts: 0
Joined: Sun Jan 25, 2015 5:01 am

Attach file from Predefined Files Collection using SendGrid

Hi Sergiy,

Yes I have read that document.

I think I get the source file using:

var SourceFile = $.get(
https://api.appery.io/rest/1/db/files...);

as per : https://getsatisfaction.com/apperyio/...

but then I think I have to read the document so I can replace the "Hi" in the variable "content" (in previous post) with the contents of the file.

How do I do this?

Can you please provide a little more detail.

thanks
James

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Attach file from Predefined Files Collection using SendGrid

You can get it from the variable reader.result

Return to “Issues”