How do i send/receive files with pure JS?

ok so I was making a cloud thing but I was confused "how do I upload and download files with JS?" I was looking on google, but none of them worked in the snap editor. can anyone help me?

There are blocks to do this in

when they say "upload files" I think they mean, "upload them to an external server". Also, you could just link them to the File import library instead of your custom blocks project.

yes i meant that
is there any external servers that i can send stuff to?

make your own with replit or something, but uploads only stay up for 14 days

but how do you do it with javascript?

to get files you can use fetch

  .then(response => response.json())
  .then(data => console.log(data));

to send files you can probably send a POST or PUT request using an XMLHttpRequest
i say "probably" because i think it is up to the server to decide what happens on a POST or PUT request

var req = new XMLHttpRequest();"POST", "");

You can also send POST or PUT requests with fetch

pumpkinhead already mentioned that.

I didn't have that link


upload is easy, use:

let i = document.createElement("input")
i.type = "file"
// when clicked
//use a filereader api to read the file
let fr = new FileReader()
// for filereader


download is harder,
You gotta make a Blob object and attach it onto a <a> tag
Blob - Web APIs | MDN for more details

I didn't either. I just searched on the forum, "file import" and in the results was "File import library".

No, download is loads easier.
Take a look:

var lnk = document.createElement('a');
lnk.href = (URL||webkitURL).createObjectURL(new Blob([contents])); // assuming contents is a var with the contents = 'test.jpg'; // name + . + extension

with the block in the

with all website except it just reports nothing

Screenshot 2021-05-29 165950
im trying to use it in snap
edit: i will try again

im trying to use it in snap

wait button tag does not work?

You need to define a variable or function parameter called data and assign to it the data you want to send.

Same thing (


Only a subset of HTML can be used on the forum (i.e. iframe for Snap! projects and text-formatting ones like p, h1-h6, b, i, strike, em, etc. [maybe more?])