Commit 792d8a31 by Pragati Upadhyay

conTentType

parent 0ef072ee
...@@ -5,7 +5,7 @@ const sharp = require('sharp') ...@@ -5,7 +5,7 @@ const sharp = require('sharp')
const fs = require('fs') const fs = require('fs')
const { createVideoFromImages,createVideo, joinAudioVideo } = require("../helper/ffmpeg-helper") const { createVideoFromImages,createVideo, joinAudioVideo } = require("../helper/ffmpeg-helper")
const { deleteFile, downloadFile } = require("../helper/utilities") const { deleteFile, downloadFile } = require("../helper/utilities")
const { generatePreSignedGetUrl, uploadToAwsS3 } = require("../helper/upload") const { generatePreSignedGetUrl,uploadThumbnailToAwsS3, uploadToAwsS3 } = require("../helper/upload")
const mongoose = require('mongoose') const mongoose = require('mongoose')
const ObjectId = mongoose.Types.ObjectId const ObjectId = mongoose.Types.ObjectId
const ffmpeg = require("fluent-ffmpeg"); const ffmpeg = require("fluent-ffmpeg");
...@@ -130,7 +130,7 @@ module.exports.generateVideo = async function (req, res) { ...@@ -130,7 +130,7 @@ module.exports.generateVideo = async function (req, res) {
let remoteThumbnailPath = path.join(CONFIG.S3_TUTOR_SHOT, thumbnailName) let remoteThumbnailPath = path.join(CONFIG.S3_TUTOR_SHOT, thumbnailName)
let url = await uploadToAwsS3(videoPath, remotePath,{contentType:'video/mp4'}) let url = await uploadToAwsS3(videoPath, remotePath,{contentType:'video/mp4'})
await uploadToAwsS3(thumbnailPath, remoteThumbnailPath) await uploadThumbnailToAwsS3(thumbnailPath, remoteThumbnailPath)
tutorShotData.thumbnailUrl = remoteThumbnailPath tutorShotData.thumbnailUrl = remoteThumbnailPath
tutorShotData.signedVideoUrl = await generatePreSignedGetUrl(remotePath) tutorShotData.signedVideoUrl = await generatePreSignedGetUrl(remotePath)
tutorShotData.signedThumbnailUrl = await generatePreSignedGetUrl(remoteThumbnailPath) tutorShotData.signedThumbnailUrl = await generatePreSignedGetUrl(remoteThumbnailPath)
......
...@@ -24,7 +24,7 @@ module.exports.uploadToAwsS3 = async function (localPath, remotePath,contentType ...@@ -24,7 +24,7 @@ module.exports.uploadToAwsS3 = async function (localPath, remotePath,contentType
Bucket: CONFIG.S3_BUCKET_NAME, Bucket: CONFIG.S3_BUCKET_NAME,
Key: remotePath, Key: remotePath,
}; };
if(contentType.contentType){ if(contentType?.contentType){
params.ContentType = contentType.contentType params.ContentType = contentType.contentType
} }
s3.putObject(params, function (err, data) { s3.putObject(params, function (err, data) {
...@@ -44,7 +44,34 @@ module.exports.uploadToAwsS3 = async function (localPath, remotePath,contentType ...@@ -44,7 +44,34 @@ module.exports.uploadToAwsS3 = async function (localPath, remotePath,contentType
return { status: httpStatus.NETWORK_ERROR, path: remotePath } return { status: httpStatus.NETWORK_ERROR, path: remotePath }
} }
} }
module.exports.uploadThumbnailToAwsS3 = async function (localPath, remotePath,options) {
const buffer = Fs.readFileSync(localPath);
try {
var params = {
Body: buffer,
Bucket: CONFIG.S3_BUCKET_NAME,
Key: remotePath,
};
s3.putObject(params, function (err, data) {
if (err) {
console.log(err);
}
// successful response
});
if (options && !options.preventUnlink) {
try { Fs.unlinkSync(localPath) }
catch (err) { console.log(err) }
}
return
} catch (error) {
console.log(error);
return { status: httpStatus.NETWORK_ERROR, path: remotePath }
}
}
module.exports.generatePreSignedGetUrl = async function (fileName) { module.exports.generatePreSignedGetUrl = async function (fileName) {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
s3.getSignedUrl('getObject', { s3.getSignedUrl('getObject', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment