Skip to content

Commit c5f3c70

Browse files
authored
address package changes (#38)
1 parent b581975 commit c5f3c70

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

app/app.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,38 +213,38 @@ app.post('/api/files', function (req, res) {
213213
res.status(500).send(err);
214214
});
215215

216-
form.on('file', async (name, file) => {
216+
form.on('file', (name, file) => {
217+
console.log(file);
217218
var fileDetails = {
218-
name: file.name,
219+
name: file.originalFilename,
219220
type: file.type,
220221
size: file.size,
221222
createdAt: new Date(),
222223
userId: getSub(req),
223224
};
224225

225-
console.log(`New file to upload: ${fileDetails.name} (${fileDetails.size} bytes)`);
226+
console.log(`New file to upload: ${fileDetails.originalFilename} (${fileDetails.size} bytes)`);
226227

227228
// create Cloudant document
228229
cloudant.postDocument({
229230
db: CLOUDANT_DB,
230231
document: fileDetails
231232
}).then(async response => {
232-
console.log(response);
233233
fileDetails.id = response.result.id;
234234

235235
// upload to COS
236236
await cos.upload({
237237
Bucket: COS_BUCKET_NAME,
238-
Key: `${fileDetails.userId}/${fileDetails.id}/${fileDetails.name}`,
239-
Body: fs.createReadStream(file.path),
238+
Key: `${fileDetails.userId}/${fileDetails.id}/${fileDetails.originalFilename}`,
239+
Body: fs.createReadStream(file.filepath),
240240
ContentType: fileDetails.type,
241241
}).promise()
242242

243243
// reply with the document
244244
console.log(`[OK] Document ${fileDetails.id} uploaded to storage`);
245245
res.send(fileDetails);
246246
// delete the file once uploaded
247-
fs.unlink(file.path, (err) => {
247+
fs.unlink(file.filepath, (err) => {
248248
if (err) { console.log(err) }
249249
});
250250
}).catch(error => {

0 commit comments

Comments
 (0)