0

I need your help with uploading an image file from google compute engine instance to google cloud storage. I have been able to move an image from a frontend form with php with the usual move_uploaded_file function but the real problem surfaces when I Try to copy that file to google cloud storage within php script using gsutil command. After quick debugging I found these results

**Tue Jan 01 04:45:12.491702 2019] [core:notice] [pid 8539] AH00094: Command line: '/usr/sbin/apache2'
sh: 1: /var/www/includes/multimediaStorage.sh/var/www/html/uploads/markii.jpg: not found
sh: 1: /var/www/includes/unloadUploads.sh/var/www/html/uploads/markii.jpg: not found
baraka_ben@igroup1us-xszd:/var/log/apache2$ cd /var/www/html/uploads/
baraka_ben@igroup1us-xszd:/var/www/html/uploads$ ls
markii.jpg
baraka_ben@igroup1us-xszd:/var/www/html/uploads$ ls -lh
total 4.0K
-rw-r--r-- 1 www-data www-data 3.0K Jan  1 04:50 markii.jpg
baraka_ben@igroup1us-xszd:/var/www/html/uploads$** 

But again, if I try the same command within the shell console ssh environment it runs smoothly without any problem as shown hereunder

baraka_ben@igroup1us-xszd:/var/www/html/uploads$ gsutil cp markii.jpg gs://bucket/Folder/SubFolder
Copying file://markii.jpg [Content-Type=image/jpeg]...
/ [1 files][  2.9 KiB/  2.9 KiB]                                                
Operation completed over 1 objects/2.9 KiB.                                      
baraka_ben@igroup1us-xszd:/var/www/html/uploads$ 

nota bene the bucket name shown here is not the actual one and the multimediaStorage.sh script contains similar command syntax to what the above code has. Now I am stranded as I Tried to figure out the folder and file ownership and permissions rights by making the "www-data" user the owner of the folder /var/www/html/uploads but it does not seem to be of any help. May you please help me to get over this hurdle. Down here is my php script part related to this question

if (!empty($_FILES['picha']) && $_FILES['picha']['error'] == UPLOAD_ERR_OK) {
   $tmpName = $_FILES['picha']['tmp_name'];
   $name = basename($_FILES['picha']['name']);
   $desnation="/var/www/html/uploads/$name";

   $message=move_uploaded_file($tmpName,$desnation);
   $repository=$desnation;
   $destiny="gs://BucketName/Folder/Subfolder/";
   $execution="/var/www/includes/multimediaStorage.sh";
   $destination ='gs:BucketName/Folder/Subfolder/'."$name";
   $combination="$repository $destiny";
   exec($execution.''.$combination);
   $clearence="/var/www/includes/unloadUploads.sh";
   array_push($Patharray,$destination);
   // unlink("/var/www/html/uploads/$filename");
   exec($clearence.''.$repository);
}

Happy New Year 2019 and THANKS IN ADVANCE!

Benedict
  • 21
  • 6
  • From what I see in your debug output, for example, /var/www/includes/multimediaStorage.sh/var/www/html/uploads/markii.jpg: not found. It is complaining for the unavailable path. So, it looks like a syntax error in your code. Please add a space string between $execution and $combination. The delimiter I see in the first exec command is just an empty string. If my guess is right, this question doesn't belong to GCP category. – mehdi sharifi Jan 02 '19 at 03:53
  • thanks Mehdi! after amending the code I got the following:ERROR: (gsutil) Failed to create the default configuration. Ensure your have the correct permissions on: [/var/www/ .config/gcloud/configurations]. Could not create directory [/var/www/.config/gcloud/configurations]: Permission denied. Please verify that you have permissions to write to the parent directory. – Benedict Jan 02 '19 at 09:18
  • from the observations above I think there is relevance to the gcp category even though not very much directly – Benedict Jan 02 '19 at 09:21
  • From your comment, it looks like the "not found" error is resolved. The new issue might be caused by the permissions associated to your user account by which you run gsutil commands on the instance. Please review [this related story](https://stackoverflow.com/questions/37441174/i-cant-init-google-cloud-sdk-on-ubuntu) on using "chown USER -R DIRECTORY" to resolve it. – mehdi sharifi Jan 08 '19 at 22:36

0 Answers0