Tuesday, 15 June 2010

web services - Salesforce/php - downloaded image attachments are corrupted - Any Ideas? -



web services - Salesforce/php - downloaded image attachments are corrupted - Any Ideas? -

here code downloading attachment salesforce.com using php toolkit , enterprise wsdl:

header('content-type: application/force-download'); header('content-disposition: inline; filename="image.jpg"'); $mysforceconnection = getconnection(); $query = "select id, name, body attachment id ='" .$id ."'"; $queryresult = $mysforceconnection->query($query); $records = $queryresult->records; print_r(base64_decode($records[0]->fields->body));

when file gets downloaded correctly right number of bytes when open image, windows image viewer says corrupt. thought why happening?

the same code works fine pdfs , text files.

you want echo output, @eyescream mentioned. when utilize print_r function, additional tab , newline characters placed output create more readable. plain echo output properly.

header('content-type: application/force-download'); header('content-disposition: inline; filename="image.jpg"'); $mysforceconnection = getconnection(); $query = "select id, name, body attachment id ='" .$id ."'"; $queryresult = $mysforceconnection->query($query); $records = $queryresult->records; echo base64_decode($records[0]->fields->body);

php web-services salesforce

No comments:

Post a Comment