I having an issue while sending a file attachment with an email and the issue is when I am sending the file as an attachment with email but when opening the file in my email it’s showing me there is an error with file content and here the snippets of code.
here is the backend code
import {fetch} from ‘wix-fetch’;
export function sendWithService(key, sender, recipient,format,file) {
const url = “https://api.sendgrid.com/api/mail.send.json”;
const headers = {
“Authorization”: "Bearer " + key,
“Content-Type”: “application/x-www-form-urlencoded”
};
const data = from =${sender}&to=${recipient}&subject=${"Testing"}&text=${"Thanks you so much sir for your response"}&files[file]=<@file>;
const request = {
“method”: “post”,
“headers”: headers,
“body”: data
}; return fetch(url, request)
.then(response => response.json());
}
here is the frontend code where I am passing the file that have to be sent as an attachment after user upload the file and click on button to upload the file.
import {sendEmail} from ‘backend/email’;
$w.onReady( function () {
});
export function button1_click(event) {
$w(‘#dataset1’).save().then((item)=>{
let ext=getFileExtension3(item.file);
sendEmail(ext,item.file).then((response)=>{
console.log(response.message)
})
})
}
function getFileExtension3(filename) { return filename.slice((filename.lastIndexOf(“.”) - 1 >>> 0) + 2);
}
Please kindly help me regarding this problem otherwise my contract got terminated with my client.
Thanks for directing me here from the other form.
Taking a look at the above, which backend file do you suggest placing your code in? I’ve tried all three of my “sendGrid”, “email”, and “data” backends and I receive several errors stating it’s unable to load the @sendgrid/mail and base 64 encode modules. Is there another backend file we should create before calling them functions we’re importing?