how to send bitmap from android to php file












-2















I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is



<?php

require "conn.php";

$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}

?>


I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?










share|improve this question

























  • Can you show us what you've tried on the Android side?

    – Luke Joshua Park
    Nov 22 '18 at 3:53
















-2















I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is



<?php

require "conn.php";

$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}

?>


I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?










share|improve this question

























  • Can you show us what you've tried on the Android side?

    – Luke Joshua Park
    Nov 22 '18 at 3:53














-2












-2








-2








I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is



<?php

require "conn.php";

$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}

?>


I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?










share|improve this question
















I'm developing an mobile android App. And I want to upload images while runtime and save thim to database. I tried alot of methods and I faild!!
whould you please help me to develop it ?
my php file is



<?php

require "conn.php";

$msg ="";
if (isset($_POST['upload']))
{
$target = "uploads/".basename($_FILES['image']['name']);
$name = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$sql = "INSERT INTO images (url) VALUES ('$name')";
mysqli_query($conn,$sql);
if(move_uploaded_file($tmp_name,$target))
{
$msg ="done";
}
else
{
$msg ="not done";
}
}

?>


I know how to save from php to database and aslo retrieve
my problem is how to send from android to PHP ?







php android android-bitmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 16 at 12:37









ankuranurag2

1,283418




1,283418










asked Nov 22 '18 at 0:01









Eman FateenEman Fateen

146




146













  • Can you show us what you've tried on the Android side?

    – Luke Joshua Park
    Nov 22 '18 at 3:53



















  • Can you show us what you've tried on the Android side?

    – Luke Joshua Park
    Nov 22 '18 at 3:53

















Can you show us what you've tried on the Android side?

– Luke Joshua Park
Nov 22 '18 at 3:53





Can you show us what you've tried on the Android side?

– Luke Joshua Park
Nov 22 '18 at 3:53












1 Answer
1






active

oldest

votes


















-1














first convert your bitmap into base64 and then send it to your server



ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);





share|improve this answer
























  • base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

    – Luke Joshua Park
    Nov 22 '18 at 3:52











  • he asked to send a bitmap in question. please read

    – Har Kal
    Nov 22 '18 at 3:53











  • Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

    – Luke Joshua Park
    Nov 22 '18 at 3:54













  • i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

    – Har Kal
    Nov 22 '18 at 3:57











  • I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

    – Luke Joshua Park
    Nov 22 '18 at 4:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422129%2fhow-to-send-bitmap-from-android-to-php-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














first convert your bitmap into base64 and then send it to your server



ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);





share|improve this answer
























  • base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

    – Luke Joshua Park
    Nov 22 '18 at 3:52











  • he asked to send a bitmap in question. please read

    – Har Kal
    Nov 22 '18 at 3:53











  • Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

    – Luke Joshua Park
    Nov 22 '18 at 3:54













  • i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

    – Har Kal
    Nov 22 '18 at 3:57











  • I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

    – Luke Joshua Park
    Nov 22 '18 at 4:01
















-1














first convert your bitmap into base64 and then send it to your server



ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);





share|improve this answer
























  • base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

    – Luke Joshua Park
    Nov 22 '18 at 3:52











  • he asked to send a bitmap in question. please read

    – Har Kal
    Nov 22 '18 at 3:53











  • Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

    – Luke Joshua Park
    Nov 22 '18 at 3:54













  • i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

    – Har Kal
    Nov 22 '18 at 3:57











  • I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

    – Luke Joshua Park
    Nov 22 '18 at 4:01














-1












-1








-1







first convert your bitmap into base64 and then send it to your server



ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);





share|improve this answer













first convert your bitmap into base64 and then send it to your server



ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte byteArray = byteArrayOutputStream .toByteArray();
String base64OfBitmap = Base64.encodeToString(byteArray, Base64.DEFAULT);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 3:46









Har KalHar Kal

612414




612414













  • base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

    – Luke Joshua Park
    Nov 22 '18 at 3:52











  • he asked to send a bitmap in question. please read

    – Har Kal
    Nov 22 '18 at 3:53











  • Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

    – Luke Joshua Park
    Nov 22 '18 at 3:54













  • i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

    – Har Kal
    Nov 22 '18 at 3:57











  • I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

    – Luke Joshua Park
    Nov 22 '18 at 4:01



















  • base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

    – Luke Joshua Park
    Nov 22 '18 at 3:52











  • he asked to send a bitmap in question. please read

    – Har Kal
    Nov 22 '18 at 3:53











  • Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

    – Luke Joshua Park
    Nov 22 '18 at 3:54













  • i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

    – Har Kal
    Nov 22 '18 at 3:57











  • I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

    – Luke Joshua Park
    Nov 22 '18 at 4:01

















base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

– Luke Joshua Park
Nov 22 '18 at 3:52





base64 makes files 33% larger. Why would you do this when you could just upload a file correctly over HTTP?

– Luke Joshua Park
Nov 22 '18 at 3:52













he asked to send a bitmap in question. please read

– Har Kal
Nov 22 '18 at 3:53





he asked to send a bitmap in question. please read

– Har Kal
Nov 22 '18 at 3:53













Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

– Luke Joshua Park
Nov 22 '18 at 3:54







Yep, I read the question and understand the problem at hand. Your solution just addresses the problem in a very inefficient way. I'm curious what benefit comes from doing it through base64 versus binary?

– Luke Joshua Park
Nov 22 '18 at 3:54















i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

– Har Kal
Nov 22 '18 at 3:57





i m just 19 and by looking at your dp u seems to be an uncle for me. i cant argue with you. i m sry. i lost. i have a huge respect for your words. good time ahead

– Har Kal
Nov 22 '18 at 3:57













I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

– Luke Joshua Park
Nov 22 '18 at 4:01





I apologise, I didn't mean to make you feel lost. Your suggested solution would definitely work, I just wanted to draw your attention to the issue!

– Luke Joshua Park
Nov 22 '18 at 4:01




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422129%2fhow-to-send-bitmap-from-android-to-php-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory