image file upload server help :(

BurakOgutkenBurakOgutken Burak OgutkenTRMember

hello
please someone will help me for upload base64 converted image how can i upload to server i am sharing my code

List<byte> rawBuffer = new List<byte>();
var contentUri = Android.Net.Uri.FromFile(_file);
using (System.IO.Stream stream = ContentResolver.OpenInputStream(contentUri))
{
byte[] buffer = new byte[4096];
int len = 0;
while ((len = stream.Read( buffer, 0, buffer.Length))> 0) {
rawBuffer.AddRange(buffer.Take(len));
}
}

string base64 = System.Convert.ToBase64String(rawBuffer.ToArray());
try
{
var webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "binary/octet-stream";
webClient.Upload(new Uri("http://xxxx.com/upload.php"),base64);

} catch (Exception ex) {
Console.Write ("{0}", ex.Message);
}

and this is upload.php

<?php
$base = $_REQUEST['data'];

echo $base;
$binary = base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen("image/test.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo '<img src=test.jpg>';
?>

please help me with code

Thanks

Posts

  • AminuddinKayaniAminuddinKayani Aminuddin Kayani MYMember
    edited May 5

    this is Just Small Piece of Code. it can send any image to your Web Server.

    System.Net.WebClient Client = new System.Net.WebClient();
    Client.Headers.Add("Content-Type", "binary/octet-stream");
    byte[] result = Client.UploadFile("localhost/FolderName/upload.php", "POST", path);
    string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
  • AminuddinKayaniAminuddinKayani Aminuddin Kayani MYMember
    edited May 5

    this is Just Small Piece of Code. it can send any image to your Web Server.

        System.Net.WebClient Client = new System.Net.WebClient();
    Client.Headers.Add("Content-Type", "binary/octet-stream");
    byte[] result = Client.UploadFile("localhost/FolderName/upload.php", "POST", path);
    string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);

    Here is the PHP Code {upload.php}. Create a Folder name { Uploads } in your Application.

    <?php

    $uploads_dir = 'uploads/'; //Directory to save the file that comes from client application.
    if ($_FILES["file"]["error"] == UPLOAD_ERR_OK)
    {
    $tmp_name = $_FILES["file"]["tmp_name"];
    $name = $_FILES["file"]["name"];
    move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
    ?>
Sign In or Register to comment.