Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

How to set content type for objects to be upload through signed url in Google Cloud Storage?

$
0
0

i'm generating signed url to upload media files using node script. But, when i check the file at storage, the file metadata is wrong like it was a multipart form data. Print from GCP Storage console demonstrate:

enter image description here

I need the files to be interpreted as media files like the print:

enter image description here

the code that i'm generating signed url:

import { GetSignedUrlConfig, Storage } from '@google-cloud/storage';import { BucketProvider } from '@shared/providers/Bucket.provider';export class CloudStorageProviderImp implements BucketProvider {  private storage: Storage;  constructor() {    this.storage = new Storage({      projectId: process.env.GCP_PROJECT_ID,    });  }  public async generateUploadSignedUrl(    bucketName: string,    fileName: string,    expireTimeInMinutes: number  ): Promise<string> {    const options: GetSignedUrlConfig = {      version: 'v4',      action: 'write',      expires: this.formatExpires(expireTimeInMinutes),      contentType: 'audio/wav'    };    const [url] = await this.storage      .bucket(bucketName)      .file(fileName)      .getSignedUrl(options)    return url;  }  private formatExpires(expireTimeInMinutes: number) {    return Date.now() + expireTimeInMinutes * 60 * 1000;  }}

The documentation of GCP is poor and until now i haven't found solutions how i can set metadata of my object to be uploaded correctly


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>