firebase / firebase/firebase-tools

Add file.getSignedUrl() support in Storage Emulator

Open
#3,400 15 comments 61 reactions 1 assignee Assigned to @abhis3 View on GitHub
emulator-suite emulators: storage help-wanted internal-bug-filed type: feature request
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### Environment info

Running inside firebase functions (also emulated)

```json
"firebase": "8.6.1",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"firebase-tools": "^9.11.0",
```

**Platform:**

macOS Big Sur 11.3.1 (20E241)

### Steps to reproduce

Inside any cloud function which processes files and needs to sign a URL:

```typescript
const [file] = await bucket.upload(tmpFilePath, { destination: output });
const signedUrl = await file.getSignedUrl({
action: 'read',
expires: addMinutes(new Date(), 60 * 24).toString(),
});
```

### Expected behavior

I receive a signed URL.

### Actual behavior

I receive this error:

```
[emulators] > {"verifications":{"app":"MISSING","auth":"MISSING"},"logging.googleapis.com/labels":{"firebase-log-type":"callable-request-verification"},"severity":"INFO","message":"Callable request verification passed"}
[emulators] > {"severity":"ERROR","message":"Unhandled error Error: Cannot sign data without `client_email`.\n at GoogleAuth.sign (/Users/jonsakas/Development/GuestHouse/guesthouse-cms/node_modules/google-auth-library/build/src/auth/googleauth.js:631:19)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)\n at async sign (/Users/jonsakas/Development/GuestHouse/guesthouse-cms/node_modules/@google-cloud/storage/build/src/signer.js:97:35) {\n name: 'SigningError'\n}"}
```

Alternatively, following the [documentation](https://firebase.google.com/docs/emulator-suite/connect_storage#node.js-admin-sdk) that says a project ID is required in the `initializeApp` I receive a different error:

```
[emulators] > {"verifications":{"app":"MISSING","auth":"MISSING"},"logging.googleapis.com/labels":{"firebase-log-type":"callable-request-verification"},"severity":"INFO","message":"Callable request verification passed"}
[emulators] > {"severity":"ERROR","message":"Unhandled error FirebaseError: Bucket name not specified or invalid. Specify a valid bucket name via the storageBucket option when initializing the app, or specify the bucket name explicitly when calling the getBucket() method.\n at new FirebaseError (/Users/jonsakas/Development/GuestHouse/guesthouse-cms/node_modules/firebase-admin/lib/utils/error.js:44:28)\n at Storage.bucket (/Users/jonsakas/Development/GuestHouse/guesthouse-cms/node_modules/firebase-admin/lib/storage/storage.js:104:15)\n at /Users/jonsakas/Development/GuestHouse/guesthouse-cms/functions/lib/http/downloadAll.js:54:35\n at async func (/Users/jonsakas/Development/GuestHouse/guesthouse-cms/node_modules/firebase-functions/lib/providers/https.js:336:26) {\n errorInfo: {\n code: 'storage/invalid-argument',\n message: 'Bucket name not specified or invalid. Specify a valid bucket name via the storageBucket option when initializing the app, or specify the bucket name explicitly when calling the getBucket() method.'\n }\n}"}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.