Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not showing when uploaded to google cloud storage #328

Open
melitus opened this issue Aug 28, 2022 · 1 comment
Open

File not showing when uploaded to google cloud storage #328

melitus opened this issue Aug 28, 2022 · 1 comment

Comments

@melitus
Copy link

melitus commented Aug 28, 2022

Get the error below when trying to view file uploaded on google cloud storage
Seem express-fileupload does not work with google cloud storage when useTempFiles : true,

I tried setting the useTempFiles: true and passing the tempFIlePath to my google cloud storage functions it did not work. I got this when an image is saved - https://storage.googleapis.com/temp-hold-eu/Z0cuwDoD6-Screenshot%25202022-08-05%2520at%252017.21.28.png. This is my code shown below

const uploadToGCS = async (
  file: Buffer,
  fileName: string,
  mimeType: string,
): Promise<string> => {
  const storage = new Storage({
    keyFilename: config.googleBucket.serviceKeyPath,
  });
  const bucket = storage.bucket(config.googleBucket.publicBucket);
  const gcsFileName = `${Date.now()}-${fileName}`;
  // Create a new blob in the bucket and upload the file data.
  const fileToUpload = bucket.file(gcsFileName);
  const fileStream = fileToUpload.createWriteStream({
    metadata: {
      contentType: mimeType,
    },
    resumable: false,
  });
  return new Promise((resolve, reject) => {
    fileStream.on('finish', () => {
      const publicUrl = getPublicUrl(encodeURIComponent(fileToUpload.name));
      fileToUpload
        .makePublic()
        .then(() => resolve(publicUrl))
        .catch(reject);
    });
    fileStream.on('error', (ex) => {
      Logger.log(ex, 'GCS');
      return reject;
    });
    fileStream.end(file);
  });
};
@RomanBurunkov
Copy link
Collaborator

Hi,

Have you done any troubleshooting with your google environment?

This doesn't looks like related to the upload middleware at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants