Skip to content

Commit

Permalink
use createReadStream: apollographql/apollo-server#2105
Browse files Browse the repository at this point in the history
  • Loading branch information
guoliu committed Mar 29, 2019
1 parent d3e4feb commit 8ca9d9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/connectors/aws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ export class AWSService {
* Upload file to AWS S3.
*/
baseUploadFile = async (folder: GQLAssetType, file: any): Promise<string> => {
const { stream, mimetype, encoding } = file
const filename = slugify(file.filename)
const {
createReadStream,
mimetype,
encoding,
filename: filenameOrigin
} = await file
const stream = createReadStream()

const filename = slugify(filenameOrigin)
const key = `${folder}/${v4()}/${filename}`
const result = await this.s3
.upload({
Expand Down
8 changes: 1 addition & 7 deletions src/mutations/system/singleFileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ const resolver: MutationToSingleFileUploadResolver = async (
{ input: { type, file } },
{ viewer, dataSources: { systemService } }
) => {
// if (!viewer.id) {
// throw new AuthenticationError('visitor has no permission')
// }

const data = await file
const { filename, mimetype, encoding } = data
const key = await systemService.aws.baseUploadFile(type, data)
const key = await systemService.aws.baseUploadFile(type, file)
const asset: ItemData = {
uuid: v4(),
authorId: viewer.id,
Expand Down

0 comments on commit 8ca9d9a

Please sign in to comment.