2015-01-03 3 views
0

Google의 클라우드 저장소에서 이미지를 버킷에 업로드 할 수 있는지 확인하려면 다음 코드를 테스트하고있었습니다.Google 버킷 ay 클라우드 저장소에 이미지 업로드

이 내 app.yaml을 파일입니다

application: test-795 
version: 1 
runtime: php 
api_version: 1 

handlers: 

# Serve images as static resources. 
- url: /(.+\.(gif|png|jpg))$ 
    static_files: \1 
    upload: .+\.(gif|png|jpg)$ 
    application_readable: true 

- url: /(.+\.php).* 
    script: \1 

- url: /upload 
    script: fileimage.php 

이것은 버킷 이미지 파일을 업로드 내 fileimage.php 파일입니다

<?php 

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; 
use google\appengine\api\cloud_storage\CloudStorageTools; 

$options = [ 'gs_bucket_name' => 'test-795.appspot.com' ]; 
$upload_url = CloudStorageTools::createUploadUrl('/upload', $options); 

    if(isset($_POST['do-upload']) AND $_POST['do-upload'] === "yes"){ 

    $yesupload = $_POST['do-upload']; 
    preg_match("/yes/", "".$yesupload.""); 

    $filename = $_FILES['testupload']['name']; 

    $gs_name = $_FILES['testupload']['tmp_name']; 
    move_uploaded_file($gs_name, 'gs://test-795.appspot.com/'.$filename.''); 
?> 

<div class="contentArea"> 
<?php 
echo "<p class=\"SomeSpaceDude\">Hey file is uploaded, Yes! ".$yesupload." !</p>"; 
echo "<p class=\"SomeSpaceDude\">This is the file name: ".$filename."</p>"; 
} 

echo"</div>"; 
?> 

<form class="SomeSpaceDude" action="<?php echo $upload_url?>" enctype="multipart/form-data" method="post"> 
<p>Files to upload: </p> <br> 
<input type="hidden" name="do-upload" value="yes"> 
<input class="SomeSpaceDude topcoat-button" type="file" name="testupload" > 
<input class="SomeSpaceDude topcoat-button" type="submit" value="Upload"> 
</form> 
</div> 

내가 로컬 호스트를 사용하여 파일을 실행할 때 : 8080 메시지가 나타납니다 안녕하세요, 파일이 업로드되었습니다. 예 ! 내 웹 주소는 다음과 같이됩니다. localhost : 8080/_ah/upload/ahVkZXZ-Y ... test-795라는 이름의 google storage에서 내 버킷을 확인하고 아무것도 업로드하지 않았습니다.

또한 배포하고 업로드 버튼을 누른 후 테스트하면 빈 페이지와 웹 주소 링크가 표시됩니다. test-795.appspot.com/_ah/upload/AMmfu6 ... 확인 중 나의 양동이 아무것도 다시는 안쪽에. 내가 여기에 무엇을 놓치고 있는지 알 수 있습니까?

답변

3

개발 서버에서 실행 중일 때 파일은 실제 Cloud Storage 서비스에 업로드되지 않고 로컬 에뮬레이션에만 업로드됩니다.

프로덕션 서버에서 업로드를 확인하려면 로그를 확인하십시오.

+0

내가 해결하려고 노력하고의 문제는 내가 위의 코드를 테스트-795 도처에서 사용해야하는, 것을 마지막으로 발견 ... 잘 작동 GCS를 로컬로 사용할 수도 있습니다. 에뮬레이트 된 버킷을 볼 수있는 방법이 있습니까? 그리고 왜 내 업로드가 실패했을까요, 배포시 100 % 작동 할 때 로컬로 실패합니까? –

1

보브 코드는 내가 대신 test-795.appspot.com

관련 문제