Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/storage/__tests__/StorageReference.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from '@jest/globals';

import Reference from '../lib/StorageReference';
import { StringFormat } from '../lib/StorageStatics';
import type { StorageInternal } from '../lib/types/internal';

describe('StorageReference string uploads', () => {
it('decodes a data URL when metadata already provides a content type', () => {
const reference = new Reference({} as StorageInternal, '/file.txt');
const metadata = { contentType: 'text/custom' };

expect(
reference._updateString('data:text/plain;base64,aGVsbG8=', StringFormat.DATA_URL, metadata),
).toEqual({
_format: StringFormat.BASE64,
_metadata: metadata,
_string: 'aGVsbG8=',
});
});
});
15 changes: 15 additions & 0 deletions packages/storage/e2e/StorageTask.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ describe('storage() -> StorageTask', function () {
uploadTaskSnapshot.metadata.should.be.an.Object();
});

it('uploads a data_url with an explicit content type', async function () {
const { getStorage, ref, uploadString, StringFormat, TaskState } = storageModular;

const uploadTaskSnapshot = await uploadString(
ref(getStorage(), `${PATH}/putStringDataURLWithContentType.txt`),
'data:text/plain;base64,aGVsbG8=',
StringFormat.DATA_URL,
{ contentType: 'text/custom' },
);

uploadTaskSnapshot.state.should.eql(TaskState.SUCCESS);
uploadTaskSnapshot.metadata.size.should.eql(5);
uploadTaskSnapshot.metadata.contentType.should.eql('text/custom');
});

it('uploads a url encoded data_url formatted string', async function () {
const { getStorage, ref, uploadString, StringFormat, TaskState } = storageModular;

Expand Down
4 changes: 2 additions & 2 deletions packages/storage/lib/StorageReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ export default class Reference extends ReferenceBase implements StorageReference
_metadata = {};
}
_metadata!.contentType = mediaType;
_string = base64String;
_format = StringFormat.BASE64;
}
_string = base64String;
_format = StringFormat.BASE64;
}
return { _string, _metadata, _format };
}
Expand Down
Loading