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

时间:2017-03-27 08:16:38

标签: php android mongodb

我从android拍摄照片并通过PHP网络服务发送。

我正在使用此代码: -

<?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"; 
}
?>

任何人都可以告诉我如何上传它。

1 个答案:

答案 0 :(得分:0)

尝试使用GenericAsyncTask进行PHP的POST。 POST将发布到PHP的内容是编码Bitmap to Base64。这是将图像发送到数据库并将其存储为字符串的简单方法。 (文件大小会大于1.2倍)