POST Attachment error : image is not valid and may be corrupted

144 views
Skip to first unread message

Shaun FISCHMANN

unread,
Jul 30, 2020, 5:49:08 AM7/30/20
to immobilienscout24-development
Hi,

I've been trying to POST attachments (images) to properties for some time now, without any success. I've looked into the PHP SDKs but it was not much help. Maybe a new perspective could help.

Headers :
      'cache-control' => 'no-cache',
      'Connection' => 'keep-alive',
      'Content-Type: multipart/form-data; boundary='.'-------------61486935'
      'Accept: application/json',
      'Accept-Encoding: gzip,deflate',
      'Authorization: OAuth ....'


The response I'm getting (HTTP 412) :
[messageCode] => ERROR_RESOURCE_VALIDATION
[message] => Error while validating input for the resource. [MESSAGE: image is not valid and may be corrupted.]

I've attached the multipart/form-data content.
I'm working mainly with JSON, but I've also tried XML, same error.
The binary data of the image is correct, I've been able to convert it back to an image using online tools.

I'm also doing a GET https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/315916648/attachment?externalId=61486935 just before, and it works (HTTP Code 200, empty because there's no image).


Sincerely,
Shaun
body_json
body_xml

Shaun FISCHMANN

unread,
Aug 17, 2020, 11:13:45 AM8/17/20
to immobilienscout24-development
Hello,

Is anybody able to help me ?


Sincerely,

Shaun FISCHMANN

unread,
Sep 14, 2020, 8:06:13 AM9/14/20
to immobilienscout24-development
Hello ? Any ideas on how to include images in POST ?

stefan....@scout24.com

unread,
Oct 5, 2020, 8:10:04 AM10/5/20
to immobilienscout24-development
Do you try to make this request with Postman?
And the configuration on the attached screenshots?
Bildschirmfoto 2020-10-05 um 14.06.47.png

Bildschirmfoto 2020-10-05 um 14.07.18.png

Shaun FISCHMANN

unread,
Oct 8, 2020, 6:08:45 AM10/8/20
to immobilienscout24-development
Hi,

I've tried using POSTMAN, but I'm not sure I understand what your configuration mean.

I've tried your configuration (check headers and body) :

Capture d’écran 2020-10-08 à 12.00.14.pngCapture d’écran 2020-10-08 à 12.00.24.png

I've tried having the attachment base64 encoded and xml metadata in the body (raw) with the multipart/form-data boundary :

Capture d’écran 2020-10-08 à 12.00.53.pngCapture d’écran 2020-10-08 à 12.01.06.png

And I've tried form-data with two files containing attachment (base64 encoded) and xml metadata :

Capture d’écran 2020-10-08 à 12.07.25.pngCapture d’écran 2020-10-08 à 12.01.45.png

Hope you can help, really appreciate any feedback.

Sincerely,
Shaun

Viacheslav Kremeshnyi

unread,
Apr 27, 2021, 7:59:34 AM4/27/21
to immobilienscout24-development
Hello Shaun,

Sorry for bothering almost one year after you asked your question you but I'm facing the same issue now and can't solve it within several days.
Did you find the solution for 412 issue? If yes it would be nice if you could share it.

I'm sending post request with raw image file data(with Content-Transfer-Encoding: binary) and getting 412 error.
Same error if I'm using Content-Transfer-Encoding: base64 header and base64 encoded image data.

Appreciate any feedback.

Sincerely,
Viacheslav
Archiv.zip

Shaun FISCHMANN

unread,
Apr 27, 2021, 8:09:46 AM4/27/21
to immobilienscout24-development
Hi Viacheslav,

Yes I was able to solve the issue recently after months of leaving this project on the side.
Instead of base64 encoding myself and building the multipart from scratch, I used CurlFile : https://www.php.net/manual/en/class.curlfile.php

$fields = [
      'metadata' => new \CurlFile($metadataPath, 'application/json', 'metadata.json'),
      'attachment' => new \CurlFile($picturePath, 'image/jpeg', 'picture.jpg')
    ];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($picturePath));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type:multipart/form-data',
      'Accept: application/json;strict=true',
      'Authorization: ...'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);


Hope this helps.
Shaun

Viacheslav Kremeshnyi

unread,
Apr 27, 2021, 11:21:12 AM4/27/21
to immobilienscout24-development
Hi Shaun,

Thank you for your help and quick reply. I wish immoscout24 support would be so fast.

One more question, I tried your code and it didn't not work for me, I'm getting 401 error.
So it's authorization issue, I'm pretty sure I'm doing this part not correct. 
Could you please tell a bit more about this part " Authorization: ...'", what exactly you put instead of ... to make it work?

I already have oauth_token because before image posting I'm posting real estate item which is working fine for me. 

Regards,
Viacheslav

Shaun FISCHMANN

unread,
Apr 27, 2021, 11:43:00 AM4/27/21
to immobilienscout24-development
You should use the same OAUTH method you used when you posted the real estate. It depends on your situation :
Reply all
Reply to author
Forward
0 new messages