From 7700df972fa3fd1c94bc67d4d4438ce26fbd2fcf Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 14:44:29 +0300 Subject: [PATCH 1/8] fix: empty file tags cause upload error for some providers DigitalOcean and Linode object storage solutions do not accept `tags` option while uploading a file. Previously, tags option was set to default empty object. Now, we do not include it if it is empty. --- src/Routers/FilesRouter.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Routers/FilesRouter.js b/src/Routers/FilesRouter.js index df768e6d0b..9010a7552d 100644 --- a/src/Routers/FilesRouter.js +++ b/src/Routers/FilesRouter.js @@ -166,16 +166,26 @@ export class FilesRouter { // update fileSize const bufferData = Buffer.from(fileObject.file._data, 'base64'); fileObject.fileSize = Buffer.byteLength(bufferData); + // prepare file options + const fileTags = fileObject.file._tags; + let fileOptions = { + metadata: fileObject.file._metadata, + }; + if (Object.keys(fileTags).length > 0) { + // some s3-compatible providers (DigitalOcean, Linode) do not accept tags + // so we do not include the tags option if it is empty. + fileOptions = { + ...fileOptions, + tags: fileTags, + }; + } // save file const createFileResult = await filesController.createFile( config, fileObject.file._name, bufferData, fileObject.file._source.type, - { - tags: fileObject.file._tags, - metadata: fileObject.file._metadata, - } + fileOptions ); // update file with new data fileObject.file._name = createFileResult.name; From 972c0e4038489de1934b15574123fab30191c6c7 Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 16:44:29 +0300 Subject: [PATCH 2/8] chore: add tests for saving a file with/without tags --- spec/ParseFile.spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/ParseFile.spec.js b/spec/ParseFile.spec.js index b55dd7404a..0f50ceb47a 100644 --- a/spec/ParseFile.spec.js +++ b/spec/ParseFile.spec.js @@ -3,6 +3,7 @@ 'use strict'; +const { FilesController } = require('../lib/Controllers/FilesController'); const request = require('../lib/request'); const str = 'Hello World!'; @@ -205,6 +206,29 @@ describe('Parse.File testing', () => { notEqual(file.name(), 'hello.txt'); }); + it('save file with tags', async () => { + spyOn(FilesController.prototype, 'createFile').and.callThrough(); + const file = new Parse.File('hello.txt', data, 'text/plain'); + file.setTags({ hello: 'world' }); + ok(!file.url()); + const result = await file.save(); + equal(result.tags(), { hello: 'world' }); + expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({ + tags: { hello: 'world' }, + metadata: {}, + }); + }); + + it('empty file tags should not be passed while saving', async () => { + spyOn(FilesController.prototype, 'createFile').and.callThrough(); + const file = new Parse.File('hello.txt', data, 'text/plain'); + ok(!file.url()); + await file.save(); + expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({ + metadata: {}, + }); + }); + it('save file in object', async done => { const file = new Parse.File('hello.txt', data, 'text/plain'); ok(!file.url()); From 20f3771177ff7723d7a1258054252f8016d6d3f1 Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 18:32:10 +0300 Subject: [PATCH 3/8] chore: update file tags handling to make tests pass --- src/Routers/FilesRouter.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Routers/FilesRouter.js b/src/Routers/FilesRouter.js index 9010a7552d..c0c7e00f13 100644 --- a/src/Routers/FilesRouter.js +++ b/src/Routers/FilesRouter.js @@ -167,18 +167,14 @@ export class FilesRouter { const bufferData = Buffer.from(fileObject.file._data, 'base64'); fileObject.fileSize = Buffer.byteLength(bufferData); // prepare file options - const fileTags = fileObject.file._tags; - let fileOptions = { + const fileOptions = { metadata: fileObject.file._metadata, }; - if (Object.keys(fileTags).length > 0) { - // some s3-compatible providers (DigitalOcean, Linode) do not accept tags - // so we do not include the tags option if it is empty. - fileOptions = { - ...fileOptions, - tags: fileTags, - }; - } + // some s3-compatible providers (DigitalOcean, Linode) do not accept tags + // so we do not include the tags option if it is empty. + const fileTags = + Object.keys(fileObject.file._tags).length > 0 ? { tags: fileObject.file._tags } : {}; + Object.assign(fileOptions, fileTags); // save file const createFileResult = await filesController.createFile( config, From 85af95b49c129a64b48748254e3af4b7ea94c002 Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 19:25:53 +0300 Subject: [PATCH 4/8] chore: refactor file tag tests --- spec/ParseFile.spec.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/ParseFile.spec.js b/spec/ParseFile.spec.js index 0f50ceb47a..8f1aff43c3 100644 --- a/spec/ParseFile.spec.js +++ b/spec/ParseFile.spec.js @@ -206,23 +206,24 @@ describe('Parse.File testing', () => { notEqual(file.name(), 'hello.txt'); }); - it('save file with tags', async () => { + it('saves the file with tags', async () => { spyOn(FilesController.prototype, 'createFile').and.callThrough(); const file = new Parse.File('hello.txt', data, 'text/plain'); - file.setTags({ hello: 'world' }); - ok(!file.url()); + const tags = { hello: 'world' }; + file.setTags(tags); + expect(file.url()).toBeUndefined(); const result = await file.save(); - equal(result.tags(), { hello: 'world' }); + expect(result.tags()).toEqual(tags); expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({ - tags: { hello: 'world' }, + tags: tags, metadata: {}, }); }); - it('empty file tags should not be passed while saving', async () => { + it('does not pass empty file tags while saving', async () => { spyOn(FilesController.prototype, 'createFile').and.callThrough(); const file = new Parse.File('hello.txt', data, 'text/plain'); - ok(!file.url()); + expect(file.url()).toBeUndefined(); await file.save(); expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({ metadata: {}, From 106288588aefa35cf7b7573c38568b2a1862995f Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 19:48:36 +0300 Subject: [PATCH 5/8] chore: update file tag tests --- spec/ParseFile.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/ParseFile.spec.js b/spec/ParseFile.spec.js index 8f1aff43c3..af1de35ee7 100644 --- a/spec/ParseFile.spec.js +++ b/spec/ParseFile.spec.js @@ -213,6 +213,8 @@ describe('Parse.File testing', () => { file.setTags(tags); expect(file.url()).toBeUndefined(); const result = await file.save(); + expect(file.name()).toBeDefined(); + expect(file.url()).toBeDefined(); expect(result.tags()).toEqual(tags); expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({ tags: tags, @@ -224,7 +226,9 @@ describe('Parse.File testing', () => { spyOn(FilesController.prototype, 'createFile').and.callThrough(); const file = new Parse.File('hello.txt', data, 'text/plain'); expect(file.url()).toBeUndefined(); + expect(file.name()).toBeDefined(); await file.save(); + expect(file.url()).toBeDefined(); expect(FilesController.prototype.createFile.calls.argsFor(0)[4]).toEqual({ metadata: {}, }); From 542dcdec60dc51d381df0b635caeff654b172827 Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 22:01:34 +0300 Subject: [PATCH 6/8] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b4422f4b4..4f9fde28bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ ___ - Excluding keys that have trailing edges.node when performing GraphQL resolver (Chris Bland) [#7273](https://github.com/parse-community/parse-server/pull/7273) - Added centralized feature deprecation with standardized warning logs (Manuel Trezza) [#7303](https://github.com/parse-community/parse-server/pull/7303) - Use Node.js 15.13.0 in CI (Olle Jonsson) [#7312](https://github.com/parse-community/parse-server/pull/7312) +- Ignore empty tags while creating a file. This fixes the file upload problem for Linode and DigitalOcean) (Ali Oguzhan Yildiz) [#7300](https://github.com/parse-community/parse-server/pull/7300) ___ ## 4.5.0 [Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0) From e79ddacee8780457055e258049f3ebf376f6ecb8 Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Sun, 28 Mar 2021 23:30:12 +0300 Subject: [PATCH 7/8] chore: update changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f9fde28bb..34d6bf3259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,6 +122,7 @@ ___ - Added centralized feature deprecation with standardized warning logs (Manuel Trezza) [#7303](https://github.com/parse-community/parse-server/pull/7303) - Use Node.js 15.13.0 in CI (Olle Jonsson) [#7312](https://github.com/parse-community/parse-server/pull/7312) - Ignore empty tags while creating a file. This fixes the file upload problem for Linode and DigitalOcean) (Ali Oguzhan Yildiz) [#7300](https://github.com/parse-community/parse-server/pull/7300) +- Fix file upload issue for S3 compatible storage (Linode, DigitalOcean) by avoiding empty tags property when creating a file (Ali Oguzhan Yildiz) [#7300](https://github.com/parse-community/parse-server/pull/7300) ___ ## 4.5.0 [Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0) From 5ddcc3c901445ca0aebb5d7f0c8bb16a86b0fa2e Mon Sep 17 00:00:00 2001 From: alioguzhan Date: Fri, 2 Apr 2021 17:58:29 +0300 Subject: [PATCH 8/8] chore: remove duplicated changelog entry --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34d6bf3259..75a80c51f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,7 +121,6 @@ ___ - Excluding keys that have trailing edges.node when performing GraphQL resolver (Chris Bland) [#7273](https://github.com/parse-community/parse-server/pull/7273) - Added centralized feature deprecation with standardized warning logs (Manuel Trezza) [#7303](https://github.com/parse-community/parse-server/pull/7303) - Use Node.js 15.13.0 in CI (Olle Jonsson) [#7312](https://github.com/parse-community/parse-server/pull/7312) -- Ignore empty tags while creating a file. This fixes the file upload problem for Linode and DigitalOcean) (Ali Oguzhan Yildiz) [#7300](https://github.com/parse-community/parse-server/pull/7300) - Fix file upload issue for S3 compatible storage (Linode, DigitalOcean) by avoiding empty tags property when creating a file (Ali Oguzhan Yildiz) [#7300](https://github.com/parse-community/parse-server/pull/7300) ___ ## 4.5.0