[SOLVED] API: 501 upload failed on /nodes/{node}/storage/{storage}/upload

cape

New Member
Mar 24, 2019
9
1
1
54
Hi,
I'm implementing file upload via the API and failing. The error is HTTP 501, with the message "upload failed", which isn't too enlightening sadly.
I can reproduce this with curl, so probably I'm doing misunderstanding how I should be making the call:

curl -X POST -H "Content-type: multipart/form-data" --form "content=iso" --form "filename=@my-disc.iso" -H 'Cookie: PVEAuthCookie=<cookie>' -H 'Csrfpreventiontoken: <token>' -k https://<my-proxmox>/api2/json/nodes/<node>/storage/local/upload

After some digging into the source and adding log output, the problem seems to be that $rstate->{md5sum} isn't initialized here: https://git.proxmox.com/?p=pve-http...d629fe5e565d197221;hb=refs/heads/master#l1090
From my reading of the code it isn't clear to me how it ever would be set, but I'm not very fluent in perl, so perhaps there is something I'm missing.

I'm running PVE 5.4, if relevant, but the code seems to be the same in PVE 6.0.

Happy for help understanding where I'm going wrong!
 
  • Like
Reactions: cogis
Hm, are you sure you are using a valid file? I just tried the curl command exactly as you posted and it worked fine for me (in PVE 6.0, mind you, but as you said, the part where it seems to be failing for you didn't change much).

The md5sum is calculated automatically here, so that shouldn't be an issue - as long as you are actually uploading a valid file, where that section of the multipart handling is called. What file are you trying to upload?
 
Interesting...
When I tested dumping a bunch of log calls in there, I never even get to processing of later phases... It goes to line 1037 which sets the phase to 2, then dies at L1091. I guess it should be looping somehow, but I didn't see how?
I'm just uploading some random text file to test out with (as full ISOs don't make testing very fast), I don't see anything validating the file type though? But dumping the request I see that it is pushing the content correctly.
 
The file type is indeed not validated, but testing some more myself, I noticed the error occurs for me too with small files (approx. <16kB it seems). Uploading a file created with dd if=/dev/urandom of=test.iso bs=16k count=1 works fine, reduce that to 8k and it fails. It seems that the multipart message is somehow incorrectly split up (and thus the "looping part" you mention is only called once), though I admit I haven't looked too deeply into that part of the code.

This is usually not a big issue, since the smallest valid ISO I could create was still ~350kB in size (using genisoimage -o test.iso /dev/null, also good for testing, since it uploads very quickly). If you want, you can still create a bug report on our bugzilla.
 
Ah, that was it! Larger file, and everything worked out nicely. Thanks!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!