我对这一切都很陌生。我正在尝试从我的iPhone应用程序中获取上传的图像,并使用PHP将其存储到我的Google云端存储桶(gs:// app / users / profile_pics /)中。我能够使用本地文件系统执行此操作,但它无法使用Google云端存储。
**iOS Code (this works)**
...
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:profile_pic_data]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
...
**PHP Code to local file system (works using local file system)**
if($_POST) {
...
//Make user directory to house files
$upload_dir = 'user_data/' . $user_id . '/';
$path = mkdir("$upload_dir", 0777);
//Save file to newly created folder
$file = 'profile_pic.jpg';
$profile_pic_path = $upload_dir . $file;
if (move_uploaded_file($_FILES['file']['tmp_name'], $profile_pic_path)) {
//Profile pic uploaded, Update profile pic field in database
$query = "UPDATE users SET profile_image_path='$upload_path' WHERE email='$user_email'";
if(mysql_query($query)){
echo json_encode(array('success' => 1,'info_message' => "")); // Account fully created!
}
...
**PHP using Google Cloud Storage (not working, trying the most simple version first)**
...
if($_POST) {
...
$gs_name = $_FILES['file']['tmp_name'];
move_uploaded_file($gs_name, 'gs://socalityapp/users/profile_pics/profile_pic.jpg');
...
我似乎无法将它存储起来。我知道我的其余部分工作正常,因为我将配置文件保存到我的Google Cloud SQL数据库中。
帮助或批评(iOS,PHP等)非常感谢!!!
答案 0 :(得分:2)
云存储与appengine不在同一台计算机上。您永远无法在appengine上使用本地文件系统。
当您收到表单提交的帖子时,您需要将图像的数据向前传递到存储。我看不到php示例,但您可以引用JSON API与存储进行交互。您应该可以使用Buzz来执行simple upload
POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=media&name=myObject