router.post('/upload', util.ensureAuthenticated, util.hasRole("admin"), uploadStrategy, (req, res) => { const blobName = getBlobName(req.file.originalname) , stream = getStream(req.file.buffer) , streamLength = req.file.buffer.length ; blobService.createBlockBlobFromStream(containerName, blobName, stream, streamLength, {contentSettings:{contentType:req.file.mimetype}} , err => { if(err) { res.status(500).json(err); } res.status(200).send(blobName); }); });
router.post('/', uploadStrategy, async (req, res) => { const blobName = getBlobName(req.file.originalname); const stream = getStream(req.file.buffer); const containerClient = blobServiceClient.getContainerClient(containerName2);; const blockBlobClient = containerClient.getBlockBlobClient(blobName); try { await blockBlobClient.uploadStream(stream, uploadOptions.bufferSize, uploadOptions.maxBuffers, { blobHTTPHeaders: { blobContentType: "image/jpeg" } }); res.render('success', { message: 'File uploaded to Azure Blob storage.' }); } catch (err) { res.render('error', { message: err.message }); } });
router.post("/upload", upload.single("file"), (req, res) => { // console.log("req.file", req.file); s3Lib.upload(req.file.originalname, req.file.buffer).then((url) => { console.log("uploaded to s3", url); mongoLib.addFile(url).then((mongoRes) => { console.log("inserted in mongo, redrecting", mongoRes); res.redirect("/"); }); }); });
savePicture(file: Express.Multer.File, id: string): Promise<PostDTO> { return new Promise((resolve, reject) => { const post = PostsRepository.getPost(id); if (!post) { return reject({code: 1, message: 'resource not found'}); } if (post.photoUrl) { return reject({code: 2, message: 'trying to edit'}); } const path = `/images/${uuid()}.png`; fs.writeFile(`public/${path}`, file.buffer, 'binary', (e: any) => { if (e) { console.error(e); return reject({code: 3, message: 'file error', ...e}); } post.photoUrl = path; PostsRepository.update(post); resolve(toDTO(post)); }); }); }
/** * POST /api/transcribe */ async function postTranscribe (req: Request, res: Response) { const bufferStream = new stream.PassThrough(); bufferStream.end( req.file.buffer ); const type = req.file.originalname.split('.').pop(); const result = await req.watsonSTT.transcribe(req.file.buffer, type, req.file.originalname, req.body.languageModel, req.body.acousticModel); if (result[0]) { req.log.error( `recognize call failed: ${JSON.stringify(result[0], null, 2)}`); return res.status(500).json({ error: result[0].code || 'failed to translate the file' }); } else { return res.status(200).json({tid: result[1]}); } }
this.router.post('/:clan/upload', util.ensureAuthenticated, util.hasRole("clanleader"), uploadStrategy, async (req, res) => { let clan = await clanService.getClanByName(req.params.clan); let account = await accountService.getAccount(req.user.name); if (!clan || clan.leader.toLowerCase() !== account.coach.toLowerCase()){ res.status(403).send(`you're not the leader of this clan, ${clan.leader} is.`); return; } const blobName = this.getBlobName(`${req.params.clan}-${req.file.originalname}`) , stream = getStream(req.file.buffer) , streamLength = req.file.buffer.length; blobService.createBlockBlobFromStream(containerName, blobName, stream, streamLength, {contentSettings:{contentType:req.file.mimetype}} , err => { if(err) { res.status(500).send(err); return; } clanService.setLogo(req.params.clan, blobName); res.status(200).send(blobName); }); });
router.post('/', uploadStrategy, async (req, res) => { const aborter = Aborter.timeout(30 * ONE_MINUTE); const blobName = getBlobName(req.file.originalname); const stream = getStream(req.file.buffer); const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); try { await uploadStreamToBlockBlob(aborter, stream, blockBlobURL, uploadOptions.bufferSize, uploadOptions.maxBuffers, { blobHTTPHeaders: { blobContentType: "image/jpeg" } }); res.render('success', { message: 'File uploaded to Azure Blob storage.' }); } catch (err) { res.render('error', { message: err.message }); } });
readableTrackStream.push(req.file.buffer); readableTrackStream.push(null);
/* Dropzone COMPONENT ajax upload file */ router.post('/file_upload', block_access.actionAccessMiddleware("COMPONENT_NAME_URL", "create"), function(req, res) { // FONCTION UPLOAD DE FICHIER DE MULTER ( FICHIER DANS req.file ) upload(req, res, function(err) { if (err) { res.status(415); return res.json({ success: false, error: "An error occured." }); } fse.mkdirsSync(config.localstorage+req.body.dataSource+"/"+req.body.dataSourceID+"/"+req.body.dataComponent); var uploadPath = config.localstorage+req.body.dataSource+"/"+req.body.dataSourceID+"/"+req.body.dataComponent+"/"+req.file.originalname; var byte; var outStream = fs.createWriteStream(uploadPath); outStream.write(req.file.buffer); outStream.end(); outStream.on('finish', function(err){ res.json({ success: true }); }); }); });
// This route is called by synchronizing devices to upload its documents // It is called right after journal synchronization success router.post('/file_upload', function(req, res) { upload(req, res, function(err) { if (err) { console.error(err) return res.status(500).end(err); } var fileName = req.file.originalname; var fileDirPath = globalConf.localstorage+req.query.entity+'/'+fileName.split('-')[0]; var filePath = fileDirPath+'/'+fileName; fs.mkdirs(fileDirPath, function (err) { if (err) { console.log(err); return res.status(500).end(err); } var outStream = fs.createWriteStream(filePath); outStream.write(req.file.buffer); outStream.end(); outStream.on('finish', function (err) { res.status(200).end(); }); }); }); });
}); stream.end(req.file.buffer);
// Process the file upload and upload to Google Cloud Storage. app.post('/upload', multer.single('file'), (req, res, next) => { if (!req.file) { res.status(400).send('No file uploaded.'); return; } // Create a new blob in the bucket and upload the file data. const blob = bucket.file(req.file.originalname); const blobStream = blob.createWriteStream({ resumable: false, }); blobStream.on('error', err => { next(err); }); blobStream.on('finish', () => { // The public URL can be used to directly access the file via HTTP. const publicUrl = format( `https://storage.googleapis.com/${bucket.name}/${blob.name}` ); res.status(200).send(publicUrl); }); blobStream.end(req.file.buffer); });
// Express route where we receive files from the client // passing multer middleware router.post('/', multerUpload.single('file'), (req, res) => { console.log('Got file:', req.file.originalname); console.log('Extra form fields:', req.body); // Send the file to Cloudinary // resource_type should be "video" for audio files! // https://cloudinary.com/documentation/image_upload_api_reference // `.end(req.file.buffer)` in this case is just passing in your buffer and indicating there won't be any further writes to the stream. cloudinary.uploader.upload_stream({ resource_type: "video" }, cloudinaryDone).end(req.file.buffer); // After the upload is completed, this callback gets called function cloudinaryDone(error, result) { if (error) { console.log("Error in cloudinary.uploader.upload_stream\n", error); return; } console.log("Cloudinary audio info: ", result.audio); // If you want to see all the data that Cloudinary comes back with // console.log(result); console.log('Cloudinary url', result.url); // Send back the working URL for the client to display. res.json({ cdn_url: result.url }); } });
async function postAudio(req: Request, res: Response) { const bufferStream = new stream.PassThrough(); bufferStream.end( req.file.buffer );
app.post('/upload', multer({storage: multer.memoryStorage()}).single("file"), async (req, res, next) => { if (req.file) { var originalname = req.file.originalname.split(' '); const fileName = originalname.join('_'); try { await minioClient.putObject('test-bucket', fileName, req.file.buffer); // get url const url = await minioClient.presignedGetObject('test-bucket', fileName); var id = uuid(); // link valid for 3 minutes (180 seconds) // save link to redis redisClient.setex(id, 180, url, (err, reply) => { if (err) { return res.json({'success': false, 'message': err}); } return res.json({'success': true, 'message': id}); }); } catch(err) { return res.json({'success': false, 'message': err}); } } });