Page 1 of 1

Attach file from Predefined Files Collection using SendGrid

Posted: Thu Oct 15, 2015 12:51 pm
by JimmyH

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


Attach file from Predefined Files Collection using SendGrid

Posted: Thu Oct 15, 2015 5:04 pm
by Evgene Karachevtsev

Hello Jimmy,

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


Attach file from Predefined Files Collection using SendGrid

Posted: Thu Oct 15, 2015 8:34 pm
by JimmyH

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


Attach file from Predefined Files Collection using SendGrid

Posted: Sat Oct 17, 2015 12:28 pm
by JimmyH

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'); 
 } 

});


Attach file from Predefined Files Collection using SendGrid

Posted: Sat Oct 17, 2015 1:27 pm
by Serhii Kulibaba

Attach file from Predefined Files Collection using SendGrid

Posted: Sat Oct 17, 2015 2:04 pm
by JimmyH

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


Attach file from Predefined Files Collection using SendGrid

Posted: Thu Oct 22, 2015 4:50 pm
by Serhii Kulibaba

You can get it from the variable reader.result