Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
2.8k views
in Plugins by
edited by

I have successfully installed Q2A on Google app engine platform with google cloud sql.

I would like site visitors to upload image files to their Questions and answers. I am using latest CKEditor4. The upload process on google app engine is bit different than Apache server/php. 

As per my research the Google app engine does not allow file to be uploded to a temperory folder on the server. Insted image file has to be uploaded to the Google cloud storage and then Q2A can transfered it to the database as blob.

Following is the example code for creating the upload url on google cloud store.

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

$options = [ 'gs_bucket_name' => 'my_bucket' ];
$upload_url = CloudStorageTools::createUploadUrl('/upload_handler.php', $options);
<form action="<?php echo $upload_url?>" enctype="multipart/form-data" method="post">
    Files to upload: <br>
   <input type="file" name="uploaded_files" size="40">
   <input type="submit" value="Send">
</form>

After the file(s) upload, a POST is made to the path specified as the first parameter to createUploadUrl; in the example above, this is /upload_handler.php. The PHP runtime forms the correct $_FILES super global, and tmp_filename refers to the filename of the newly uploaded file in GCS.

----------------------------------------------------------------------------------------------------------------------------------------------------

Can anyone please explain how can I setup CKEditor temperory upload folder to the google cloud store and also update the $_Files. Once I get the $_files uploaded I think Q2A can transfer the files to the database.

Thanks!

----------------------------------------------------------------------------------------------------------------------------------------------------

Following is my investigation update:

By default ckeditor filebrowserImageUploadUrl action is set to the following:

http://appsiteid1.appspot.com/?qa=wysiwyg-editor-upload&qa_only_image=1&CKEditor=content&CKEditorFuncNum=0&langCode=en

As per the google cloud storage image upload procedure a $upload_url is created for 10 minutes using CloudStorageTools::createUploadUrl('/upload_handler.php', $options) (as explained above)

A typical file upload url to google cloud storage looks like below: NOtice the bold part starting from _ah is some type of authentication key for uploading files and can not be altered.

http://appsiteid1.appspot.com/_ah/upload/AMmfu6YUz1XXnV31GrKSXy1J2Kn7ROwZeV_8Mghp6CsedBdEQueMLjFTJleF-oQKp12GkzulVbBzd7A_trPH6LeSSIexGp4w4yYXn9lnRuOCF9LYtAvNVDPH6DALSOBz9RhzdPQdfsghdakdcPu3VDsppQ137ln-_JghR4g-kWlr3Tzs9mr6XVnKuXNTbjpJtnhWH_M6b74hJ3GtgUw19ZomC3yHVfQi40nA/ALBasasasAAAAUzBUJ6u-GMoPoHKYglKJektWJ2fTjO9y/

So to achieve this i changed the qa-ckeditor4.php file filebrowserImageUploadUrl parameters to the $upload_url. Then I get the following:

http://appsiteid1.appspot.com/_ah/upload/?qa=ask/AMmfu6a89jdywvv1cwTHs75Fs-MLMCHowSLH7VC1b3bnuTirZahZNLDnoPyMEg4bsynl_ryt7SnVchRtKKL1f_vGCJD6JtCiseT1mtQTaA_z5guUsLBdosw1kyeMHet5H-fdv1fcWeXVRMMRiPA4aL-n1zI3sOeSvDoU8y4-OA1ClREq04UClGl2H96ukKBRakBelIXr1Y4Q/ALBNUaYAAAAAUzBU-gyeYpivxebzGtPuYhMezt9qgqAg/&qa_only_image=1&CKEditor=content&CKEditorFuncNum=0&langCode=en

As mentioned the authentication key should not be altered, see parameters added in red. It gives me 500 server internal error bacause of mismatch. 

Question is how can I remove the parameters highlighted in red and do the POST. After successful upload google app engine automatically creates $_FILES global variable with cloud storage raference. Here on Q2A can copy the data to blob table as usual.

Q2A version: 1.6.3
by
Can I ask you why you don't use directly the google cloud sql ? Cost or any technical issue/reason ?
by
I am using google cloud sql to store image blobs. But As I mentioned earlier Google app engine does not allow temporary folder on its web server for image upload thats why I have to use google cloud storage for uploading the images, once uploaded to cloud sql then it can be transferred to cloud sql using q2a code.

Correct me if I am wrong but Q2A needs a temporary directory to upload image then transfers it to the database?

Basically I am trying to understand the Q2A (CKEditor) upload process so that I can modify to upload to google cloud storage instead to a server temp directory. Also ckeditor.js is minified so i can not change it effectively.

2 Answers

+1 vote
by
selected by
 
Best answer
I don't know Google cloud app. But, information below may be useful for you...?

http://docs.ckeditor.com/#!/guide/dev_file_browse_upload

Really, Q2A core handles uploaded files in $_FILES. Below is process route in case of CKEditor4.

=> "Image Upload Dialog"
=> qa-plugin/ckeditor4/qa-ckeditor4-upload.php::match_request()
=> qa-plugin/ckeditor4/qa-ckeditor4-upload.php::process_request()
=> qa-include/qa-app-upload.php::qa_upload_file_one()  // You can't override
=> qa-include/qa-app-upload.php::qa_upload_file() // You can override

Because it is necessary to change the reference(GET) process of uploaded images, I think your demand is difficult.
by
edited by
Thanks Sama55.

I don't think i need to override qa_upload_file_one() and qa_upload_file() functions because the image data will ultimately be stored in the could sql (similar to MYSQL)

I would like to modify the temporary upload location (not sure how, which js or php file to modify) to cloud storage using google cloud storage API as mentioned in my question.

Also, as per the app engine documentation, after the file upload, a POST is made to the path specified as the first parameter to createUploadUrl; in the example above, this is /upload_handler.php. (I am thinking this could be qa-ckeditor4-upload.php).

As long as file gets upload to the Google cloud storage and PHP runtime forms the correct $_FILES super global, and tmp_filename refers to the filename of the newly uploaded file in GCS it should be fine.

Just for the information: There were similar issues with installing WordPress on GAE in the beginning but now there is a Google app engine plugin to take care of app engine dependent APIs such as Email, memcache, image upload and storage.

Similar plugins are being developed for Drupal so why not develop a plugin for Q2A?
by
See my updates to the question. Any help would be highly appreciated.
+1 vote
by

The temporary folder used by the CKEditor should be that set in your php.ini

by
Hi, Thanks for the link. Google app engine disables the upload_tmp_dir even if you setup in php.ini. Please refer to the link below:
http://stackoverflow.com/questions/19716469/google-app-engine-php-files-array-empty-tried-everything-others-have-sugge
I think the only option is to upload to the cloud storage and then process it.

Please help.
...