简体   繁体   English

如何使用php web服务将图像从android上传到mongodb

[英]how to upload image from android to mongodb using php web servies

I'm taking the picture from android and sending via PHP web services. 我正在从android拍照,并通过PHP网络服务发送。

I'm using this code:- 我正在使用此代码:

<?php
//creating mongodb database connection
$m = new MongoClient();
$db = $m->companydb;
$grid= $db->getGridFS('myGrid');
//creating for request
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $pic = $_POST['image'];
    //uploading in mongodb database
    // we are getting error in this line -->This function work properly when              

    we are taking image from html file and use this command
    //storeUpload('image'); but in this file first we are string in a variable         
    and then passing this variable using storeUpload function 
    // maybe thats why we are geeting this issue
    $grid->storeUpload($pic);
    echo "Successfully Uploaded";
} 
else{
    echo "please check the REQUEST_METHOD"; 
}
?>

Can anybody please tell me how to upload it. 有人可以告诉我如何上传吗?

Try to use GenericAsyncTask for POST to the PHP. 尝试将GenericAsyncTask用于POST至PHP。 And POST what you will post to the PHP is an encoded Bitmap to Base64 . POST将发布到PHP的内容是Base64的编码位图 That's a simple way to send images to database and store them as a string. 这是将图像发送到数据库并将其存储为字符串的一种简单方法。 (The file size will be bigger with ~1.2x) (文件大小将约为1.2倍)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM