fix: empty file tags cause upload error for some providers (#7300)
* 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. * chore: add tests for saving a file with/without tags * chore: update file tags handling to make tests pass * chore: refactor file tag tests * chore: update file tag tests * chore: update changelog * chore: update changelog entry * chore: remove duplicated changelog entry
This commit is contained in:
committed by
GitHub
parent
626352d594
commit
4d167026ae
@@ -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)
|
- 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)
|
- 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)
|
- Use Node.js 15.13.0 in CI (Olle Jonsson) [#7312](https://github.com/parse-community/parse-server/pull/7312)
|
||||||
|
- 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
|
## 4.5.0
|
||||||
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
|
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { FilesController } = require('../lib/Controllers/FilesController');
|
||||||
const request = require('../lib/request');
|
const request = require('../lib/request');
|
||||||
|
|
||||||
const str = 'Hello World!';
|
const str = 'Hello World!';
|
||||||
@@ -205,6 +206,34 @@ describe('Parse.File testing', () => {
|
|||||||
notEqual(file.name(), 'hello.txt');
|
notEqual(file.name(), 'hello.txt');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('saves the file with tags', async () => {
|
||||||
|
spyOn(FilesController.prototype, 'createFile').and.callThrough();
|
||||||
|
const file = new Parse.File('hello.txt', data, 'text/plain');
|
||||||
|
const tags = { hello: 'world' };
|
||||||
|
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,
|
||||||
|
metadata: {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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');
|
||||||
|
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: {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('save file in object', async done => {
|
it('save file in object', async done => {
|
||||||
const file = new Parse.File('hello.txt', data, 'text/plain');
|
const file = new Parse.File('hello.txt', data, 'text/plain');
|
||||||
ok(!file.url());
|
ok(!file.url());
|
||||||
|
|||||||
@@ -166,16 +166,22 @@ export class FilesRouter {
|
|||||||
// update fileSize
|
// update fileSize
|
||||||
const bufferData = Buffer.from(fileObject.file._data, 'base64');
|
const bufferData = Buffer.from(fileObject.file._data, 'base64');
|
||||||
fileObject.fileSize = Buffer.byteLength(bufferData);
|
fileObject.fileSize = Buffer.byteLength(bufferData);
|
||||||
|
// prepare file options
|
||||||
|
const fileOptions = {
|
||||||
|
metadata: fileObject.file._metadata,
|
||||||
|
};
|
||||||
|
// 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
|
// save file
|
||||||
const createFileResult = await filesController.createFile(
|
const createFileResult = await filesController.createFile(
|
||||||
config,
|
config,
|
||||||
fileObject.file._name,
|
fileObject.file._name,
|
||||||
bufferData,
|
bufferData,
|
||||||
fileObject.file._source.type,
|
fileObject.file._source.type,
|
||||||
{
|
fileOptions
|
||||||
tags: fileObject.file._tags,
|
|
||||||
metadata: fileObject.file._metadata,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
// update file with new data
|
// update file with new data
|
||||||
fileObject.file._name = createFileResult.name;
|
fileObject.file._name = createFileResult.name;
|
||||||
|
|||||||
Reference in New Issue
Block a user