image create full of nil
HelloWaow opened this issue · comments
Hi,
I'm trying to add an image to an item but I have a problem. All the element are Nil:
` image = Craftar::Image.create(item: item.resource_uri, file: lienImgOrig)
=> #<Craftar::Image:0x0000000624f0a8 @uuid=nil, @item=nil, @file=nil, @resource_uri=nil, @name=nil, @status=nil, @thumb_120=nil, @thumb_60=nil, @tracking_data_status=nil>`
If anyone has the solution it could be very helpfull!!
Thank
Have a nice day
This issue is due to an invalid request sent to the server. The HTTMultiparty module (unmantained now) is nesting the parts twice by adding a boundary around the parts created for the POST request:
The body of the multipart POST request should be like:
--PZlQOTHTCqbiBlcd
Content-Disposition: form-data; name="api_key"
cedb43af16414f890cba69d0dd539298fc19d2fe
--PZlQOTHTCqbiBlcd
Content-Disposition: form-data; name="file"; filename="biz_card20181203-35620-jiekyg.jpe"
Content-Type: application/octet-stream
����JFIF��C
.... JPEG FILE
--PZlQOTHTCqbiBlcd
Content-Disposition: form-data; name="item"
/api/v0/item/f30e73fcc9ca460d88428807a62a67ca/
--PZlQOTHTCqbiBlcd--
The HTTMultiparty library is generating a request that wraps that as a single part with a DEFAULT_BOUNDARY = "-----------RubyMultipartPost"
boundary around it and also overrides the content_type to include this boundary.
I created a fork with a quick and dirty fix for this (I'm no ruby developer). What I think should be done is to find a proper replacement for HTTMultiparty or just not use it and do it with HTTParty (probably already supports multipart POST).