I want to write a function that create a CSV file to save it in the Cloud Storage then return the download url to the frontend. After reading for 1 day there is no similar question as I want to:
exports.createCSV = functions.https.onRequest((req, res) => {
return cors(req, res, async () => {
let csv = ''
const { location } = req.body.report
const {
postcode, streetAddress, city, state,
} = location.address
const header = []
header.push('First Name')
header.push('Last Name')
header.push('Postcode')
header.push('Street Address')
header.push('City')
header.push('State')
header.push('Start')
header.push('End')
header.push('Status')
csv += header.join(';')
csv += '\n'
await Promise.all(
report.shifts.map(async shift => {
const row = []
row.push(firstName)
row.push(lastName)
row.push(postcode)
row.push(streetAddress)
row.push(city)
row.push(state)
row.push(shift.startStr)
row.push(shift.endStr)
row.push(shift.status)
csv += row.join(';')
csv += '\n'
return null
}),
)
})
})
But then how to save it in the Cloud Storage and get the download url is the problem to me at this point :(
I use the function as Frank below suggest:
await bucket.upload(tempLocalFile, {
destination: filePath,
metadata: {
metadata: {
...metadata,
firebaseStorageDownloadTokens: uuidv4(),
},
},
})
const file = bucket.file(fileName);
file.getSignedUrl({
action: "download",
expires: "03-09-2491",
}).then((signedUrls) => {
console.log("URL URL URL: ", signedUrls);
});
It still not working as Error return like
Error: The action is not provided or invalid. at File.getSignedUrl