1

I'm not sure what I'm doing wrong. When I run the API calls directly from the front-end, everything works great however it exposes the API KEY, so I'm moving all functions on firebase cloud functions and for some reason the formData return empty when posting.

Front-End

let formData = new FormData();
formData.append("file", e.target.files[0], name);
formData.append("deal_id", deal.id);

console.log(formData.get("file"));

(async () => {
  console.log("call");
  const response = await props.putFiles({ formData });
  document.querySelector(`#Y${name}`).classList.add("uploaded");
  uploadedComplete(name);
  setUploading({
    ...uploading,
    [name]: false,
  });
  console.log(response);
})();

Cloud Function

exports.putFiles = functions.https.onCall(async (data, context) => {
   return data.formData;
});
Outcast
  • 99
  • 3
  • 12
  • Have you tried with `const response = await props.putFiles(formData);` instead of `const response = await props.putFiles({ formData });` and sending it like `return data;` instead of `data.fromData` – Sandeep Vokkareni Feb 22 '23 at 15:06
  • Yes, I've tried that even though Callables take an object. so when I do this `const anObject = {dude: "car"}; const response = await props.putFiles({ formData: anObject });` it'll spit out the object but when I put the form Data it returns as empty. I thought maybe the async messes with the order in which JS interprets the data so it's empty and it sends it... I also tried this `const anObject = { form: formdata.get("file") };` and pass `anObject` which logs perfectly, and that also returns as empty. I'm puzzled. – Outcast Feb 22 '23 at 16:58
  • https://firebase.google.com/docs/functions/callable – Outcast Feb 22 '23 at 17:05

0 Answers0