Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
const { filename, encoding, mimetype } = file
const headers = {
'Content-Type': mimetype,
'Content-Encoding': encoding,
}
return await this.http.put(
routes.FileUpload(bucket, filename),
stream,
{
headers,
}
)
} catch (e) {
const status = e.statusCode || path(['response', 'status'], e) || 500
throw new ResolverError(e, status)
}
}
return sessionQueries.getSession(null, null, context).then(currentSession => {
const session = currentSession as SessionFields
if (!session || !session.id) {
throw new ResolverError('Error fetching session data')
}
const profile =
session.impersonate && session.impersonate.profile
? session.impersonate.profile
: session.profile
return profile
? ({
email: profile && profile.email,
userId: profile && profile.id,
} as CurrentProfile)
: null
})
}
public constructor(ioContext: IOContext, options: InstanceOptions = {}) {
super('vtex.file-manager', ioContext, { ...options, timeout: 5000 })
if (runningAppName === '') {
throw new ResolverError(
`Invalid path to access FileManger. Variable VTEX_APP_ID is not available.`
)
}
}
formData.append(field, buffer, {
contentType: mimetype,
filename: randomName,
knownLength: buffer.byteLength,
})
const response = await masterdata.uploadAttachment(
acronym,
documentId,
field,
formData
)
if (response) {
throw new ResolverError(response)
}
return { filename: randomName, mimetype }
}