By scare-me

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.


@scare-me 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

37 Answered Questions

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

53 Answered Questions

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

69 Answered Questions

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

  • 2011-04-23 22:17:18
  • Walker
  • 5215299 View
  • 6520 Score
  • 69 Answer
  • Tags:   javascript arrays

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
  • 2015243 View
  • 1683 Score
  • 27 Answer
  • Tags:   javascript

10 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
  • 590311 View
  • 1222 Score
  • 10 Answer
  • Tags:   javascript arrays

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

3 Answered Questions

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

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

1 Answered Questions

Sponsored Content