because it’s the only thing that really uses the “upload” function. So I want to learn how it works and maybe use it to make an early version of SAFE-FS for desktop
So I’m gonna use this thread for some ?'s here and there
and @joshuef I might have asked you a long time ago but I forgot. Do you remember a way to upload files with safe-js? I know the createOrUpdateFile but I think that would require me to convert every file (images, video etc) into text which would be quite crazy. Do you remember if there was an upload command in the safe-js you made?
Internet is working, since I’m posting here, and I’m logged in with Launcher v.11 but nothing can auth with it. Anyone else having these TEST16 problems?
I haven’t made time to work on test 16 or to connect to it with the respective browser binary. Will you paste your error into a post so that I can see what’s happening?
name doens’t appear to be defined in your js code, so that’ll likely throw an error…
FYI: from your code it looks like the only data you’re writing is the file name (contentzz.value is not the file’s data, just the location of the file on the computer take a look at the html5 file api here ).
The problem of trying to work with projects with zero documentation…
If you feel it’s not clear I’m happy to accept a PR with improvements (But I’m not maintaining safe-js as it’ll be superseded by new libs from maidsafe themselves and won’t be useful at all come mutable data, sorry!).
What is the “name?” name of the file being updated?
If so I can just make a variable that maps it to my html browse files button
Also, just updated my function but still not quite working. Added that var name = line giving it a basic “name” just for now, to try and get one file uploaded successfully:
function uplode(){
if(!auth){
alert('Please Login First');
return;
}
var contennts = (document.getElementById('content').value);
if(contennts==""){
alert('Please Choose a File');
return;
}
var name = "CURRENTUPLOADFILE";
var contentzz = (document.getElementById('content').value).trim();
safeNFS.createOrUpdateFile(auth.token,name,contentzz,dataType='text/plain').then(function(response){
document.getElementById('fileresponse').innerHTML = '"'+(document.getElementById('content').value).trim()+'"';
var elems = document.getElementsByTagName("input");
var l = elems.length;
for (var i = 0; i < l; ++i){
elems[i].value="";
}
},function(error){
//console.log(error);
document.getElementById('fileresponse').innerHTML = "Error Uploading File";
});
}
Helper function to make or update a file as no current method exists to do this in the SAFE API at this point.
Either creates a file if it doesn’t exist, or deletes and recreates with the new content if it does already exist.
token - (string) auth token
filePath - (string) file path
dataToWrite - data of file being uploaded
dataType - (string - optional), type of data being uploaded. text/plain for example.
dataLength - (int - optional) length of data being written.
metadata - (base64 string - optional) metadata for the dir.
isPathShared - (bool - optional) true if writing to the sharedDRIVE, false writes to APP;
Returns a Promise which resolves truthy upon success.
So the second param should be the file path on safe.
Guess that was all I needed, was give the name var.
Now I’ll try playing with it!
Something that would really help is if there’s a way to make a function that will allow uploading .txt files, and .png and .anything all in one file? Is the dataType=Text/Plain part limiting that?
maybe I can just delete the dataType part? I’ll try that