tentwentyfour / nextcloud-link

Javascript/Typescript client that communicates with Nextcloud's WebDAV and OCS APIs
MIT License
56 stars 7 forks source link

How can i upload a file to my nextcloud? #50

Closed NicoloLattanzio closed 1 year ago

NicoloLattanzio commented 2 years ago

Hello, i just started using this library, but using this: await client.uploadFromStream("https://cloud.kanbanbox.com/index.php/f/938709","screenshot");

Doesnt do anything, shouldnt it upload the file?

kwisatz commented 2 years ago

Hi @NicoloLattanzio

Could you please try to create a minimal (failing) example that we could actually run from a command line? From your line above, it's hard for us to judge if you e.g. passed the correct type of argument to the uploadFromStream function.

It expects a stream as second argument and we can't know from your example if "screenshot" is a reference to a stream or not. Also note that the path argument must be a relative, existing path, not a URL. (See https://github.com/tentwentyfour/nextcloud-link#core)

NicoloLattanzio commented 2 years ago

It says "argument type is not assignable to stream.Readable

NicoloLattanzio commented 2 years ago

I dont have a console error, it just dont upload

NicoloLattanzio commented 2 years ago

What do u mean with "existing path"? I'm trying to insert a folder with other file inside, into a nextcloud folder, im using the internal link as a path

floriansimon1 commented 2 years ago

I brlieve the function expects a stream, not a path. Is that correct?

NicoloLattanzio commented 2 years ago

Honestly, i'm not understanding what u mean with "stream"

NicoloLattanzio commented 2 years ago

Maybe something like this? const stream = fs.createReadStream('screenshot/ScreenshotAPP/kanban/de/2022-6-30 8356_kanban_de.png') await client.uploadFromStream("https://cloud.kanbanbox.com/index.php/f/938709",stream); But it's still not working

floriansimon1 commented 2 years ago

What about put?

NicoloLattanzio commented 2 years ago

Already tried, but is it useful to upload file?

floriansimon1 commented 2 years ago

I'd assume so, but then again, I haven't touched the module in a while.

NicoloLattanzio commented 2 years ago

Idk, i did this but isnt working: await client.put("https://cloud.kanbanbox.com/index.php/s/***********","screenshot/ScreenshotAPP/kanban/de/2022-6-30 8356_kanban_de.png");

floriansimon1 commented 2 years ago

Oh right, sorry. The path you're passing is a network URL. You need to either dowbload the file OR create a HTTP stream that you'd use uploadFromStream with

NicoloLattanzio commented 2 years ago

Mmmm what do u mean? I actually just need to upload it, so i think the thing missing is the stream, but i still dont understand what it is

floriansimon1 commented 2 years ago

Have a look at this: https://nodejs.org/api/stream.html

Stack Overflow might also help you here.

kwisatz commented 2 years ago

Please @NicoloLattanzio do not use github tickets as a form of chat. We are all trying to do our very best to concentrate both on our paid work and helping out, but receiving an email every 2 minutes isn't helping.

Please do not post again unless you can supply a complete source code snippet and the full error output that you see. Please also consider the following:

Your client object is already connected (it should be, see our Getting Started section), as a given user, to your nextcloud server. Which means that https://cloud.kanbanbox.com/index.php is irrelevant here.

If the user that you used to connect to your nextcloud server is for instance nicolo, then the path that uploadFromStream expects is the relative path, including the target filename to your user's home directory. No external or internal share links, but just the path. E.g. Documents/Images/Examples/image.png.

If you don't know what a stream is, we suggest you read up on that in the node.js documentation.

NicoloLattanzio commented 2 years ago

Well, the full code i wrote is this: Immagine 2022-06-30 151909 I'm trying both the function put and uploadstreamreadable, i tried to create the stream u were talking about but i guess this isnt the right way. By the way, where should i find the path? Like, i have just a folder called "Application Screenshot"

lattam commented 2 years ago

If you have one folder in your nextcloud instance and it is called "Application Screenshot", then you can use it as a target path. Also, the put method accepts actual file content as the second parameter, not the path.

const content = fs.readFileSync('/path/somewhere/on/your/machine/screenshot.jpeg');

await client.put("/Application Screenshot", content);
NicoloLattanzio commented 2 years ago

Actually i did this, it works perfectly when loading a text file, but i cant load an image, as it need the image content(data), do u know how to do this? Or maybe there are other way to load an image gfdgfd ?