다음 코드는 메타 데이터가 포함 된 이미지를 Picasa 웹 앨범에 업로드하려고 시도하고 있습니다.메타 데이터가있는 사진을 Picasa에 업로드하려고 할 때 'Multipart에 Atom 및 미디어 부분이 있어야 함'오류가 발생합니다.
아래의 코드는 메타 데이터를 가져 와서 콘텐츠 유형 : image/jpeg POST 요청을하면 이미지를 업로드하는 데 적합합니다.
$albumUrl = "https://picasaweb.google.com/data/feed/api/user/$userId/albumid/$albumId";
$imgName = $_SERVER['DOCUMENT_ROOT'] . '/picasa/cute_baby_kitten.jpg';
$rawImgXml = '<entry xmlns="http://www.w3.org/2005/Atom">
<title>plz-to-love-realcat.jpg</title>
<summary>Real cat wants attention too.</summary>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/photos/2007#photo"/>
</entry>';
$fileSize = filesize($imgName);
$fh = fopen($imgName, 'rb');
$imgData = fread($fh, $fileSize);
fclose($fh);
$dataLength = strlen($rawImgXml) + $fileSize;
$data = "";
$data .= "\nMedia multipart posting\n";
$data .= "--P4CpLdIHZpYqNn7\n";
$data .= "Content-Type: application/atom+xml\n\n";
$data .= $rawImgXml . "\n";
$data .= "--P4CpLdIHZpYqNn7\n";
$data .= "Content-Type: image/jpeg\n\n";
$data .= $imgData . "\n";
$data .= "--P4CpLdIHZpYqNn7--";
$header = array('GData-Version: 2', $authHeader, 'Content-Type: multipart/related;boundary=P4CpLdIHZpYqNn7', 'Content-Length: ' . $dataLength, 'MIME-version: 1.0');
$ret = "";
$ch = curl_init($albumUrl);
$options = array(
CURLOPT_SSL_VERIFYPEER=> false,
CURLOPT_POST=> true,
CURLOPT_RETURNTRANSFER=> true,
CURLOPT_HEADER=> true,
CURLOPT_FOLLOWLOCATION=> true,
CURLOPT_POSTFIELDS=> $data,
CURLOPT_HTTPHEADER=> $header
);
curl_setopt_array($ch, $options);
$ret = curl_exec($ch);
curl_close($ch);
문제
내가400 Bad Request: Multipart must have Atom and media part
오류 메시지가 다시 점점 계속 것입니다.
Array
(
[0] => GData-Version: 2
[1] => Authorization: GoogleLogin auth="THISISAVALIDAUTHCODE"
[2] => Content-Type: multipart/related;boundary=P4CpLdIHZpYqNn7
[3] => Content-Length: 179951
[4] => MIME-version: 1.0
)
을 그리고 여기처럼 POST 요청 본문 보이는 내용은 다음과 같습니다 : 나는 라인이 제대로 POST 본문에 배치 나누기 생각
Media multipart posting
--P4CpLdIHZpYqNn7
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom">
<title>plz-to-love-realcat.jpg</title>
<summary>Real cat wants attention too.</summary>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/photos/2007#photo"/>
</entry>
--P4CpLdIHZpYqNn7
Content-Type: image/jpeg
IMAGE DATA GOES HERE
--P4CpLdIHZpYqNn7--
여기
는 헤더 내가 보내고있다 있습니다 하지만 나는 100 % 확실하지 않습니다. 나는 또한 정확하게Content-Length
을 계산했는지 궁금합니다.
내가 뭘 잘못하고 있니?