ruby on rails - How can I use curl to upload a file using paperclip? -
i want upload file information(e.g. package_type) curl
in submission
model:
has_attached_file :package
what tried:
curl -d "submission[package_type]=type1&submission[package]=@/home/ubuntu/downloads/test.zip" http://localhost:3000/restapi.json
if leave out file object, works(a entry inserted database)
but specify file above, gives me error:
no handler found "@/home/ubuntu/downloads/test.zip"
update:
i found that should use -f
option in curl, in case file information cannot recorded, there anyway include both file object , file info? maybe curl -d -f
?
i had similar issue , ended setting content-type multipart/form-data instead of dealing base64 encoding issues when posting rest api. here example includes headers auth:
curl -v -h 'content-type: multipart/form-data' -h "x-user-email: <email>" -h "x-user-token: <token>" -x post -i -f submission[package_type]=type1 -f submission[image_attributes][image]=@f117.jpg http://localhost:3000/api/v1/submissions
Comments
Post a Comment