Curl URL syntax for uploading files

24 Views Asked by At

I'm trying to replace a picture in NetBox by uploading a replacement picture using curl. I'm finding that depending on which form of the URL I use, I get different error messages.

Note that I get the same error messages if I use PUT instead of PATCH.

The file is only 4Mb and is in the current directory.

File is owned by me and has the following permissions: -rwxrwxrwx

The file I am trying to replace has an object_id in NetBox of 3852.

Here is the curl command I am using:

curl \
 --request PATCH \
 https://my.netbox.com/api/extras/image-attachments/3852/ \
 --verbose \
 --cacert "mycert.pem" \
 --header "Content-Type: multipart/form-data" \
 --header "Authorization: Token mytoken" \
 --Form "content_type=dcim.rack" \
 --Form "object_id=3852" \
 --Form "name=replacement.jpg" \
 --Form "[email protected];type=image/jpg" \
 --Form "image_height=3024" \
 --Form "image_width=4032"

Here are the error messages I get with different forms of the URL:

https://my.netbox.com/api/extras/image-attachments/3852/ 
 * We are completely uploaded and fine
 {"non_field_errors":["Invalid parent object: dcim | rack ID 3852"]}
https://my.netbox.com/api/extras/image-attachments/3852
 * We are completely uploaded and fine
 < HTTP/1.1 301 Moved Permanently
https://my.netbox.com/api/extras/image-attachments/
   <p>
     There was a problem with your request. Please contact an administrator.
   </p>
 
 <hr />
 <p>
   The complete exception is provided below:
 </p>
 <pre class="block"><strong>&lt;class &#x27;AttributeError&#x27;&gt;</strong><br />
 &#x27;str&#x27; object has no attribute &#x27;pop&#x27;
https://my.netbox.com/api/extras/image-attachments
 * We are completely uploaded and fine
 < HTTP/1.1 301 Moved Permanently

None of these seem to actually upload a file even with the message: We are completely uploaded and fine

How should I format the URL to make this work?

0

There are 0 best solutions below