-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): Add
getDownloadUrl
method to the Storage API (#2036)
- Loading branch information
Showing
7 changed files
with
210 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { File } from '@google-cloud/storage'; | ||
export interface FirebaseMetadata { | ||
name: string; | ||
bucket: string; | ||
generation: string; | ||
metageneration: string; | ||
contentType: string; | ||
timeCreated: string; | ||
updated: string; | ||
storageClass: string; | ||
size: string; | ||
md5Hash: string; | ||
contentEncoding: string; | ||
contentDisposition: string; | ||
crc32c: string; | ||
etag: string; | ||
downloadTokens?: string; | ||
} | ||
|
||
export function getFirebaseMetadata( | ||
endpoint: string, | ||
file: File | ||
): Promise<FirebaseMetadata> { | ||
const uri = `${endpoint}/b/${file.bucket.name}/o/${encodeURIComponent( | ||
file.name | ||
)}`; | ||
|
||
return new Promise((resolve, reject) => { | ||
file.storage.makeAuthenticatedRequest( | ||
{ | ||
method: 'GET', | ||
uri, | ||
}, | ||
(err, body) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(body); | ||
} | ||
} | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters