Skip to content

Commit 9634efd

Browse files
authored
Add nonresumable uploadBytes to modular Storage (#4084)
1 parent 8518b6b commit 9634efd

30 files changed

+1019
-573
lines changed

common/api-review/storage.api.md

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
## API Report File for "@firebase/storage"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { FirebaseApp } from '@firebase/app-types';
8+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
9+
import { FirebaseError } from '@firebase/util';
10+
import { _FirebaseService } from '@firebase/app-types';
11+
import { Provider } from '@firebase/component';
12+
import * as types from '@firebase/storage-types';
13+
14+
// @public
15+
export function deleteObject(ref: StorageReference): Promise<void>;
16+
17+
// @public
18+
export function getDownloadURL(ref: StorageReference): Promise<string>;
19+
20+
// @public
21+
export function getMetadata(ref: StorageReference): Promise<Metadata>;
22+
23+
// @public
24+
export function getStorage(app: FirebaseApp): StorageService;
25+
26+
// @public
27+
export function list(ref: StorageReference, options?: ListOptions | null): Promise<ListResult>;
28+
29+
// @public
30+
export function listAll(ref: StorageReference): Promise<ListResult>;
31+
32+
// @public
33+
export interface ListOptions extends types.ListOptions {
34+
}
35+
36+
// @public
37+
export interface ListResult {
38+
// (undocumented)
39+
items: StorageReference[];
40+
// (undocumented)
41+
nextPageToken?: string;
42+
// (undocumented)
43+
prefixes: StorageReference[];
44+
}
45+
46+
// @public
47+
export interface Metadata extends types.FullMetadata {
48+
// (undocumented)
49+
[prop: string]: unknown;
50+
// (undocumented)
51+
cacheControl: string | undefined;
52+
// (undocumented)
53+
contentDisposition: string | undefined;
54+
// (undocumented)
55+
contentEncoding: string | undefined;
56+
// (undocumented)
57+
contentLanguage: string | undefined;
58+
// (undocumented)
59+
contentType: string | undefined;
60+
// (undocumented)
61+
customMetadata: {
62+
[key: string]: string;
63+
} | undefined;
64+
// (undocumented)
65+
downloadTokens: string[] | undefined;
66+
// (undocumented)
67+
md5Hash: string | undefined;
68+
// (undocumented)
69+
ref: StorageReference | undefined;
70+
// (undocumented)
71+
type: string | undefined;
72+
}
73+
74+
// @public
75+
export function ref(storage: StorageService, url?: string): StorageReference;
76+
77+
// @public
78+
export function ref(storageOrRef: StorageService | StorageReference, path?: string): StorageReference;
79+
80+
// @public
81+
export class StorageReference {
82+
constructor(_service: StorageService, location: string | Location_2);
83+
// (undocumented)
84+
get bucket(): string;
85+
// (undocumented)
86+
get fullPath(): string;
87+
// Warning: (ae-forgotten-export) The symbol "Location" needs to be exported by the entry point index.d.ts
88+
//
89+
// @internal (undocumented)
90+
_location: Location_2;
91+
// (undocumented)
92+
get name(): string;
93+
// (undocumented)
94+
protected newRef(service: StorageService, location: Location_2): StorageReference;
95+
// (undocumented)
96+
get parent(): StorageReference | null;
97+
// (undocumented)
98+
get root(): StorageReference;
99+
// (undocumented)
100+
get storage(): StorageService;
101+
// (undocumented)
102+
_throwIfRoot(name: string): void;
103+
// @override (undocumented)
104+
toString(): string;
105+
}
106+
107+
// @public
108+
export class StorageService implements _FirebaseService {
109+
constructor(app: FirebaseApp,
110+
_authProvider: Provider<FirebaseAuthInternalName>,
111+
_pool: XhrIoPool,
112+
_url?: string | undefined,
113+
_firebaseVersion?: string | undefined);
114+
// (undocumented)
115+
readonly app: FirebaseApp;
116+
// (undocumented)
117+
protected readonly _appId: string | null;
118+
// @internal (undocumented)
119+
readonly _authProvider: Provider<FirebaseAuthInternalName>;
120+
// @internal (undocumented)
121+
readonly _bucket: Location_2 | null;
122+
// @internal
123+
_delete(): Promise<void>;
124+
// @internal (undocumented)
125+
readonly _firebaseVersion?: string | undefined;
126+
// (undocumented)
127+
getAuthToken(): Promise<string | null>;
128+
// Warning: (ae-forgotten-export) The symbol "RequestInfo" needs to be exported by the entry point index.d.ts
129+
// Warning: (ae-forgotten-export) The symbol "Request" needs to be exported by the entry point index.d.ts
130+
//
131+
// @internal (undocumented)
132+
makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null): Request_2<T>;
133+
makeStorageReference(loc: Location_2): StorageReference;
134+
// (undocumented)
135+
get maxOperationRetryTime(): number;
136+
set maxOperationRetryTime(time: number);
137+
// (undocumented)
138+
get maxUploadRetryTime(): number;
139+
set maxUploadRetryTime(time: number);
140+
// Warning: (ae-forgotten-export) The symbol "XhrIoPool" needs to be exported by the entry point index.d.ts
141+
//
142+
// @internal (undocumented)
143+
readonly _pool: XhrIoPool;
144+
// @internal (undocumented)
145+
readonly _url?: string | undefined;
146+
}
147+
148+
// @public
149+
export type StringFormat = string;
150+
151+
// @public
152+
export const StringFormat: {
153+
RAW: string;
154+
BASE64: string;
155+
BASE64URL: string;
156+
DATA_URL: string;
157+
};
158+
159+
// @public
160+
export function updateMetadata(ref: StorageReference, metadata: Record<string, unknown>): Promise<Metadata>;
161+
162+
// @public
163+
export function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): Promise<UploadResult>;
164+
165+
// @public
166+
export function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): UploadTask;
167+
168+
// @public
169+
export interface UploadResult {
170+
// (undocumented)
171+
readonly metadata: Metadata;
172+
// (undocumented)
173+
readonly ref: StorageReference;
174+
}
175+
176+
// @public
177+
export function uploadString(ref: StorageReference, value: string, format?: StringFormat, metadata?: Metadata): Promise<UploadResult>;
178+
179+
// @public
180+
export class UploadTask {
181+
constructor(ref: StorageReference, blob: FbsBlob, metadata?: Metadata | null);
182+
// Warning: (ae-forgotten-export) The symbol "FbsBlob" needs to be exported by the entry point index.d.ts
183+
//
184+
// @internal (undocumented)
185+
_blob: FbsBlob;
186+
cancel(): boolean;
187+
catch<T>(onRejected: (p1: FirebaseStorageError) => T | Promise<T>): Promise<T>;
188+
// @internal (undocumented)
189+
_metadata: Metadata | null;
190+
// Warning: (ae-forgotten-export) The symbol "TaskEvent" needs to be exported by the entry point index.d.ts
191+
// Warning: (ae-forgotten-export) The symbol "StorageObserver" needs to be exported by the entry point index.d.ts
192+
// Warning: (ae-forgotten-export) The symbol "ErrorFn" needs to be exported by the entry point index.d.ts
193+
// Warning: (ae-forgotten-export) The symbol "CompleteFn" needs to be exported by the entry point index.d.ts
194+
// Warning: (ae-forgotten-export) The symbol "Unsubscribe" needs to be exported by the entry point index.d.ts
195+
// Warning: (ae-forgotten-export) The symbol "Subscribe" needs to be exported by the entry point index.d.ts
196+
on(type: TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | ((a: UploadTaskSnapshot) => unknown), error?: ErrorFn, completed?: CompleteFn): Unsubscribe | Subscribe<UploadTaskSnapshot>;
197+
pause(): boolean;
198+
resume(): boolean;
199+
// (undocumented)
200+
get snapshot(): UploadTaskSnapshot;
201+
// Warning: (ae-forgotten-export) The symbol "InternalTaskState" needs to be exported by the entry point index.d.ts
202+
//
203+
// @internal (undocumented)
204+
_state: InternalTaskState;
205+
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageError" needs to be exported by the entry point index.d.ts
206+
then<U>(onFulfilled?: ((value: UploadTaskSnapshot) => U | Promise<U>) | null, onRejected?: ((error: FirebaseStorageError) => U | Promise<U>) | null): Promise<U>;
207+
// @internal (undocumented)
208+
_transferred: number;
209+
}
210+
211+
// @public
212+
export interface UploadTaskSnapshot {
213+
// (undocumented)
214+
readonly bytesTransferred: number;
215+
// (undocumented)
216+
readonly metadata: Metadata;
217+
// (undocumented)
218+
readonly ref: StorageReference;
219+
// Warning: (ae-forgotten-export) The symbol "TaskState" needs to be exported by the entry point index.d.ts
220+
//
221+
// (undocumented)
222+
readonly state: TaskState;
223+
// (undocumented)
224+
readonly task: UploadTask;
225+
// (undocumented)
226+
readonly totalBytes: number;
227+
}
228+
229+
230+
// (No @packageDocumentation comment for this package)
231+
232+
```

packages/storage/compat/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ function factory(
5151
// of creating a new one.
5252
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
5353
app,
54-
new StorageService(app, authProvider, new XhrIoPool(), url)
54+
new StorageService(
55+
app,
56+
authProvider,
57+
new XhrIoPool(),
58+
url,
59+
firebase.SDK_VERSION
60+
)
5561
);
5662
return storageServiceCompat;
5763
}

packages/storage/compat/reference.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
*/
1717

1818
import {
19-
Reference,
19+
StorageReference,
2020
getChild,
2121
uploadBytesResumable,
22-
uploadString,
2322
list,
2423
listAll,
2524
getDownloadURL,
@@ -29,16 +28,18 @@ import {
2928
} from '../src/reference';
3029
import * as types from '@firebase/storage-types';
3130
import { Metadata } from '../src/metadata';
32-
import { StringFormat } from '../src/implementation/string';
31+
import { dataFromString, StringFormat } from '../src/implementation/string';
3332
import { ListOptions } from '../src/list';
3433
import { UploadTaskCompat } from './task';
3534
import { ListResultCompat } from './list';
3635
import { StorageServiceCompat } from './service';
3736
import { invalidRootOperation } from '../src/implementation/error';
37+
import { UploadTask } from '../src/task';
38+
import { FbsBlob } from '../src/implementation/blob';
3839

3940
export class ReferenceCompat implements types.Reference {
4041
constructor(
41-
private readonly _delegate: Reference,
42+
private readonly _delegate: StorageReference,
4243
public storage: StorageServiceCompat
4344
) {}
4445

@@ -114,8 +115,17 @@ export class ReferenceCompat implements types.Reference {
114115
metadata?: Metadata
115116
): types.UploadTask {
116117
this._throwIfRoot('putString');
118+
const data = dataFromString(format, value);
119+
const metadataClone = { ...metadata } as Metadata;
120+
if (metadataClone['contentType'] == null && data.contentType != null) {
121+
metadataClone['contentType'] = data.contentType;
122+
}
117123
return new UploadTaskCompat(
118-
uploadString(this._delegate, value, format, metadata),
124+
new UploadTask(
125+
this._delegate,
126+
new FbsBlob(data.data, true),
127+
metadataClone
128+
),
119129
this
120130
);
121131
}

packages/storage/exp/index.ts

+37-7
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,76 @@
1515
* limitations under the License.
1616
*/
1717

18-
// eslint-disable-next-line import/no-extraneous-dependencies
19-
import { _registerComponent, registerVersion } from '@firebase/app-exp';
18+
import {
19+
_registerComponent,
20+
registerVersion,
21+
_getProvider,
22+
SDK_VERSION
23+
// eslint-disable-next-line import/no-extraneous-dependencies
24+
} from '@firebase/app-exp';
2025

2126
import { XhrIoPool } from '../src/implementation/xhriopool';
2227
import { StorageService } from '../src/service';
2328
import {
2429
Component,
2530
ComponentType,
26-
ComponentContainer
31+
ComponentContainer,
32+
Provider
2733
} from '@firebase/component';
2834

2935
import { name, version } from '../package.json';
36+
import { FirebaseApp } from '@firebase/app-types-exp';
3037

31-
export { ref } from '../src/service';
38+
export { ref, StorageService } from '../src/service';
3239
export {
40+
uploadBytes,
3341
uploadBytesResumable,
3442
uploadString,
3543
getMetadata,
3644
updateMetadata,
3745
list,
3846
listAll,
3947
getDownloadURL,
40-
deleteObject
48+
deleteObject,
49+
StorageReference
4150
} from '../src/reference';
51+
export { Metadata } from '../src/metadata';
52+
export { ListOptions, ListResult } from '../src/list';
53+
export { UploadTask } from '../src/task';
54+
export { UploadResult, UploadTaskSnapshot } from '../src/tasksnapshot';
55+
export { StringFormat } from '../src/implementation/string';
4256

4357
/**
4458
* Type constant for Firebase Storage.
4559
*/
4660
const STORAGE_TYPE = 'storage-exp';
4761

48-
function factory(container: ComponentContainer, url?: string): StorageService {
62+
/**
63+
* Gets a Firebase StorageService instance for the given Firebase app.
64+
* @public
65+
* @param app - Firebase app to get Storage instance for.
66+
* @returns A Firebase StorageService instance.
67+
*/
68+
export function getStorage(app: FirebaseApp): StorageService {
4969
// Dependencies
70+
const storageProvider: Provider<'storage-exp'> = _getProvider(
71+
app,
72+
STORAGE_TYPE
73+
);
74+
const storageInstance = storageProvider.getImmediate();
75+
return storageInstance;
76+
}
77+
78+
function factory(container: ComponentContainer, url?: string): StorageService {
5079
const app = container.getProvider('app-exp').getImmediate();
5180
const authProvider = container.getProvider('auth-internal');
5281

5382
return (new StorageService(
5483
app,
5584
authProvider,
5685
new XhrIoPool(),
57-
url
86+
url,
87+
SDK_VERSION
5888
) as unknown) as StorageService;
5989
}
6090

packages/storage/exp/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"main": "./dist/index.browser.cjs.js",
55
"module": "./dist/index.browser.esm2017.js",
66
"browser": "./dist/index.browser.esm2017.js",
7-
"typings": "./dist/index.d.ts",
7+
"typings": "./dist/storage.d.ts",
88
"private": true
99
}

0 commit comments

Comments
 (0)