Using an uploaded asset from a node script


#1

I’m building an app that allows users to upload a csv and then process it with a Node script. Because they also have to add some credentials, I’m instructing them to Remix my app so they can upload the file and edit their own .env. I was hoping they could simply drag and drop their csv into the project view, but from my understanding this uploads it to the assets “folder” which doesn’t actually live inside the project, but behind a separate CDN. This means the node script can’t simply load those files with fs.

What is the best way to work around this? I know I could probably create a page that lets users upload the file and use a server to save it to the app instead of assets, but I’d prefer to avoid that if possible.

Thanks!


#2

We don’t have a great solution for this at the moment - we plan to revisit how we handle assets soon.

In the meantime, one option is once uploaded to assets using wget from the console to import that file locally, however, that’s not a great option for inexperienced users.

Another option would be to have a blank CSV file in your template project, that your users then copy and paste the contents of their CSV file into after remixing. This might be easier to understand and they wouldn’t need to change the filename in the code to match their file.


#3

Yeah, the goal is to make this as accessible as possible for non-technical users so the console isn’t an option. Sort of similarly, I think most people don’t even realize a .csv is actually a text file they can open to edit, especially since by default it would open in Excel or Numbers instead of a text editor.

Maybe a compromise would be to let them upload it to assets and then instruct them to copy/paste the link into a text field on the page which fetches the file from the server side? Not as seamless as I’d like but easier than building a file uploader.


#4

@Gareth I was just writing instructions for the upload & copy+paste solution I mentioned above, and noticed that my csv file is uploading directly into the project root now instead of going into assets. Did something change? This is exactly the behavior I want but I’m not sure why it’s happening.

I took a little video of it: https://www.dropbox.com/s/luj3679uie9v3v3/tweet-upload.mov?dl=0


#5

Yes, that’s right - it was available quicker than I thought, but you can now upload some file types like csv, txt, js etc. to the local filesystem with drag and drop.


#6

:open_mouth:

Amazing! That was the last hurdle I needed to figure out in my app so this is very exciting. Thank you!


#7

@Gareth bumping this topic because I’ve noticed an interesting issue.

Some people who are remixing my app https://glitch.com/~twitter-archive-deleter are getting the new behavior where the .csv is uploaded directly to the project root (what I want to happen), but some people are still getting the old behavior where it’s uploaded to assets instead. For example: https://glitch.com/edit/#!/vivid-numeric you can see the tweets.csv was uploaded to assets. That user sent me a copy of the same file, and when I remixed the app myself and drag and dropped their file, it goes correctly to the project root instead of assets https://glitch.com/edit/#!/magnificent-dormouse.


#8

@ryangiglio this may be related to how they got the file there. I’m not able to reproduce getting the file to the asset drawer by drag-and-drop (and haven’t seen that in a whole bunch of drag-and-drops over the last while) but there is an “Add asset” button in the asset drawer that will upload directly to the asset drawer instead of to the file list. I know your directions say “drag and drop” but directions aren’t always followed…

If you have another user encounter this it would be helpful to know the browser / OS details - maybe something weird about a particular environment?


#9

Yeah, I’m not able to reproduce it either. This was the one user in question - it SOUNDS like he followed the directions but maybe not! https://twitter.com/antimeria/status/1075460440128405504

I’ve followed up with a few other people who reported this as well so I’ll update you when I find out more from them.


#10

Yeah that sure sounds like they dragged and dropped. Let us know if you find anything, or have any details to send along so that we can take a closer look.


#11

He’s using Chrome 55.0.2883.87 on Windows 7


#12

Sure enough, dragging and dropping in Chrome on Windows 7 also adds it to assets for me. Just reproduced at https://glitch.com/edit/#!/piquant-birth?path=README.md:1:0


#13

I don’t have Windows 7 handy, but can repro from a Windows 8.1 device. Using the Upload button from the New File menu behaves the same. That’s pretty far outside of our typical support, and we’re likely to be changing the way assets and uploaded files work pretty significantly in the not-too-distant future, so I don’t think this is likely to be worked on, but I’ll bring it to the team.

While it’s not convenient, affected users could use wget in the console after the file’s been uploaded to Assets to “move” it to the right place. We can also help out by “moving” the file for them (so can anyone invited to Join the project that’s on a more recent OS) - I’m happy to do that on a case by case basis but can’t commit to it for a large contingent.

I can put together a quick screencast of the wget process if that would be helpful.


#14

Oh, actually, a way easier work-around (at least on Win8.1) is to rename the file to tweets.txt, drag-and-drop, then rename in the filelist.

Can you ask them to try that?


#15

Yeah, I wouldn’t expect the team to bother fixing a Win7 bug. No worries.

And anyway, that workaround worked for me as well - I’ll let him know and if it works I’ll add it to the instructions.


#16

That worked for him! Great find, thanks for looking into it :slight_smile: