By creep-story

2018-09-14 09:47:35 8 Comments

I need to upload a photo (png) located locally on my assets folder to Firebase (DaaS). Now as stated in the docs i need to make a new Filetype for it.
enter image description here

But how would I set such a filetype for my local img? The path of the image is this:


Does anyone have a suggestion?


I managed to create a reference to the file with this:

const defaultPhoto: HTMLImageElement = new Image();
defaultPhoto.src = '../../../../assets/no_photo_avatar.png';

But now I need to convert it it to a new File() or new Blob() type.


@creep-story 2018-09-14 16:10:41

To convert the image type to a filetype I did this - full solution:

  upload(): Promise<void> {
     const defaultPhoto: HTMLImageElement = new Image();
     defaultPhoto.src = '../../../../assets/no_photo_avatar.png';
     return srcToFIle(defaultPhoto.src,, 'image/png').then() => ...) <= firebase methods

  private srcToFile(src, fileName, mimeType): Promise<File> {
     return (fetch(src)
    .then(res => res.arrayBuffer())
    .then(buf => new File([buf], fileName, {type: mimeType})));


btw. the typings are typescript syntax.

Related Questions

Sponsored Content

76 Answered Questions

[SOLVED] How do I remove a particular element from an array in JavaScript?

  • 2011-04-23 22:17:18
  • Walker
  • 5490280 View
  • 6813 Score
  • 76 Answer
  • Tags:   javascript arrays

11 Answered Questions

[SOLVED] How can I add new array elements at the beginning of an array in Javascript?

  • 2011-11-10 00:35:22
  • Moon
  • 634300 View
  • 1285 Score
  • 11 Answer
  • Tags:   javascript arrays

53 Answered Questions

[SOLVED] How do I include a JavaScript file in another JavaScript file?

37 Answered Questions

[SOLVED] How do I remove a property from a JavaScript object?

3 Answered Questions

[SOLVED] How do I remove a key from a JavaScript object?

  • 2010-08-11 04:59:03
  • Martin Ongtangco
  • 711517 View
  • 1002 Score
  • 3 Answer
  • Tags:   javascript

27 Answered Questions

[SOLVED] Open a URL in a new tab (and not a new window) using JavaScript

  • 2011-02-05 15:52:13
  • Mark F
  • 2108103 View
  • 1741 Score
  • 27 Answer
  • Tags:   javascript

14 Answered Questions

[SOLVED] What is the 'new' keyword in JavaScript?

1 Answered Questions

Access android assets folder using javascript file

0 Answered Questions

Firebase storage save files privately for app use only

1 Answered Questions

Sponsored Content