rejetto forum

How to allow POST file upload to non-existing path?

0 Members and 1 Guest are viewing this topic.

Offline nachum37

  • Occasional poster
  • *
    • Posts: 3
    • View Profile
Hi Everyone,

Sorry for my noob question. I have Data Logger that uploads CSV files to a predefined, unchangeable URL.
When I try to send the files to HFS, the log says that the server has disconnected. Using Wireshark I saw that HFS returns a 404 Not Found error.

Of course I set up an upload folder with the required permissions, and I manage to upload through the browser, and also with the Postman test. I guess, but I'm not sure, the problem here is that the device can't upload files by POST with a URL to a path that does not exist in advance, that looks something like:
http:\\IP\DEVICE_UUID\signal_log\DATE\DATE_AND_TIME.CSV
(I turned here the slash so I could write the URL)

How do I enable the upload of files?

Is it necessary to write a script that will accept the call and generate the path? If so please please refer me to such example? Or in another way?

Thank you all.


Offline bmartino1

  • Tireless poster
  • ****
    • Posts: 910
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
How are you uiplading the file to HFS???

Are you going to hfs web page folder and clicking the uplaod button?

IF not, there is your problems.

Other wise we have to edit and chage some scritps to faciualt your needs by goin to a webpage selecting the file and uploading the data via a pst request:
http://rejetto.com/forum/index.php?topic=12122.msg1062964#msg1062964
*simple contact template has some solution for you to pull the code and re write.

--
you have to have these folder path in order to uplad adn the first - last folder having upload permision:
DEVICE_UUID\signal_log\DATE\

add a real folder to HFS > Righte mouse click > Protperties > permision tab > Upload tab > (set anyone for open folder to the web for upload.

LOG:
7:42:21 AM 10.0.0.50:1437 Requested GET /Upload/
7:42:21 AM 10.0.0.50:1438 Requested GET /?mode=jquery
7:42:24 AM 10.0.0.50:1439 Requested GET /Upload/
7:42:24 AM 10.0.0.50:1440 Requested GET /?mode=jquery
7:42:44 AM 10.0.0.50:1441 Uploading lock pc.bat
7:42:44 AM 10.0.0.50:1441 Fully uploaded lock pc.bat - 40 @ 7.8 KB/s
7:42:44 AM 10.0.0.50:1441 Requested POST /Upload/
7:42:59 AM 10.0.0.50:1437 Requested GET /Upload/
7:42:59 AM 10.0.0.50:1441 Requested GET /?mode=jquery

see picture for result on client side to upload...
« Last Edit: April 04, 2019, 12:48:09 PM by bmartino1 »
Files I have snagged and share can be found on my google drive:

https://drive.google.com/drive/folders/1qb4INX2pzsjmMT06YEIQk9Nv5jMu33tC?usp=sharing


Offline nachum37

  • Occasional poster
  • *
    • Posts: 3
    • View Profile
Thank you for your answer.
upload via webpage upload button work perfectly.

I'm try to allow IoT Device upload automatically via POST HTTP Request, not manually via web page.
 
The Path, like DEVICE_UUID\signal_log\DATE\ is dynamically changed by the specific device and the date, is it impossible to create the path in advance and give him the permissions. i'm searching for the way to create the path by the URL of the POST request, or accept the file upload anyway to some directory, instead returning 404.



The path can be one of the following:
WISE4012_1234\signal_log\20190102\2235.csv
WISE4000_4321\signal_log\20190312\2031.csv

etc...

Thanks


Offline LeoNeeson

  • Tireless poster
  • ****
    • Posts: 842
  • Status: On hiatus (sporadically here)
    • View Profile
    • twitter.com/LeoNeeson
Hi! :) this question is more for Mars, SilentPliz or Rejetto (than for me), but I could give you a possible "orientation". I'm not expert on macros, but I think this could be done by using HFS's macros. First, you should make (with a text editor) a file named "hfs.events" (and save it along to "hfs.exe").

The contents of that "hfs.events" could be something like (this is just a crazy theory, NOT actual working code):

Code: [Select]
[request]
{.if|{.header|{.is substring|POST|%item-resource%.}|{:
  {.if not|{.exists|%item-resource%.}|{:
    {.mkdir|{.filepath|%item-resource%.}
    {.add to log|I've created the folder %item-resource%.}
  :}.}
:}.}

» The idea is: read from the header of the POST HTTP Request, the destination folder. Then, if the destination folder doesn't exists, we create the folder. Keep in mind the code posted above is NOT working (the working script it's MUCH complex than that!).

» Another approach is 'somehow' (with a different macro script), when a folder doesn't exists, the file is uploaded to a temporary folder. Then, when the upload is completed, we create the desired folder (reading the destination folder from the original POST HTTP Request), and finally we move the uploaded file from the temporary folder to the new created folder.

(I hope someone else, expert on macros, could give you a hand)
Cheers,
Leo.-
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
» Currently taking a break, until HFS v2.4 get his stable version.


Offline nachum37

  • Occasional poster
  • *
    • Posts: 3
    • View Profile
Hi Leo,
Thank you very much for your reply.

This is indeed what I wanted to find out, can I solve the problem by macro of HFS. I'm glad it's possible.

I will thank anyone who can direct me to the exact script that can be written.


Offline bmartino1

  • Tireless poster
  • ****
    • Posts: 910
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
so yes this can be macro coded. My curent working theory on the mater. as i don't have time to test and cod such a thing...

you will have to have Your iot device send the data via htmp Fake php strings... add url secondary data via a ? and post url red write data via & ...

-----------------
This is why i also sent you to a working post method
i sent you leo simple contact template as that has the codes you will need to modify for the macro code/hfs side to accept the url string.

------------------

Hfs base line:
You will have to create a vitural folder in HFS

You will have to code a Macro script form

----------------------
You wil lhave to setup the iot to talk to the vitural folder sending a url full string example:
(Pulled form a sucessful post of the url data sent to hfs via macro write - with is wht you would use to post upload)

you will send the requested data via example: /Contact/?name=Brandon+Martino&email=my@test.com&subject=ff&message=pass+pass+pas&SubmitMessage=something
**********

so your sending data via the field on your virtual folder script.
[DEVICE_UUID\signal_log\DATE\]

decoding the example log and breakdown via url sending(the ### would be the data the iot device is sending...)

THis would be example of what your iot device making the request might look like
http://hfs-ip/Vituralfolder/?field-UUID=#####&Nextfield-SignalLog=######&Nextfield-date=######&nextfield-file=file.cvs

IOT would send something like this via your previos post

http://xxx.xxx.xxx.xxx/vituralfolder/?UUID=WISE4012_1234&Signallog=signal_log&date=20190102&file=2235.csv
----------------

HFS setup:

the viturl folder can use a macro to take the field
field-UUID=#####
Nextfield-SignalLog=######
Nextfield-date=######

and creat a realfolder via macro script
http://www.rejetto.com/wiki/index.php/HFS:_scripting_commands
mkdir | A
creates the specified folder. URI is supported in A, but it must refer a real folder.

then uplaod the cvs file to hfs:
nextfield-file=file.cvs

Code: [Select]
{.save|/%folder%/Private-Message-{.time|yyyy.mm.dd'-at-'hh.nn.ss.}
you could even skip some field formt eh form for the date.

this is the best i can do for yo on short notice
Files I have snagged and share can be found on my google drive:

https://drive.google.com/drive/folders/1qb4INX2pzsjmMT06YEIQk9Nv5jMu33tC?usp=sharing