[WP8.1][C#]Why when I try to upload an Image with Windows Phone it uploads a random thing?
I'm trying to upload an image from my Windows Store App (Windows Phone 8.1) to hosting (using PHP) but always when I "uploaded" the image, and I check its result the "image" it's a corrupted file. I think it's related to the byte array
conversion but I haven't found another way to do it. This is my code:
C# Code:
byte[] ConvertBitmapToByteArray()
WriteableBitmap bmp = bitmap;
using (Stream stream = bmp.PixelBuffer.AsStream())
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
public async Task<string> Upload()
try
using (var client = new HttpClient())
using (var content =
new MultipartFormDataContent())
byte[] data = ConvertBitmapToByteArray();
content.Add(new StreamContent(new MemoryStream(data)), "userfile", fileNewImage);
using (
var message =
await client.PostAsync("http://xplace.com/uploadtest.php", content))
var input = await message.Content.ReadAsStringAsync();
return input;
catch (Exception ex)
return null;
PHP code:
<?php
header('Content-Type: application/json');
$uploaddir = getcwd();
$uploadfile = $uploaddir . "/" . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo '{"result": "sucessfull"}';
} else {
echo '{"result": "-1"}';
}?>
I wish someone could give me an idea about what I my mistake and how to fix it. Thanks in advance for your worthy knowledge.
Federico Navarrete
This is the answer to the problem someone gave me an idea that I have missed to translate to BMP.
byte[] ConvertBitmapToByteArray()
WriteableBitmap bmp = bitmap;
using (Stream stream = bmp.PixelBuffer.AsStream())
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
public async Task<string> Upload()
try
using (var client = new HttpClient())
using (var content =
new MultipartFormDataContent())
byte[] data = ConvertBitmapToByteArray();
using (var stream = new InMemoryRandomAccessStream())
// encoder *outputs* to stream
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
// encoder's input is the bitmap's pixel data
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight,
(uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight, 96, 96, data);
await encoder.FlushAsync();
content.Add(new StreamContent(stream.AsStream()), "userfile", fileNewImage);
using (
var message =
await client.PostAsync("http://xplace.com/uploadtest.php", content))
var input = await message.Content.ReadAsStringAsync();
return input;
catch (Exception ex)
return null;
Now I have a different problem that after I uploaded the Image to Azure, I cannot execute the PHP code this one:
$uploaddir = getcwd();
$uploadfile = $uploaddir . "/" . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
chmod($uploadfile, 0755);
$Test = new Display($_FILES['userfile']['name']);
echo '{"result": "' . $Test->getNumber($_REQUEST['color'], false) . '"}';
//unlink($uploadfile);
} else {
echo '{"result": "-1"}';
I'd like to know what could be my bug because I don't understand why I can access from the URL, too to bit I cannot use it, maybe it's how I assigned the permissions but with or without the chmod, it
doesn't change at all. I have even tried other hostings and the problem is the same when I enter to the File Manager, there are only my PHP files and it doesn't allow me to manage the image.
Thanks for your worthy knowledge and experience.
Federico Navarrete
Similar Messages
-
When I tried to sync my iPod Touch with my new computer none of the photographs were synced. I use Adobe Photoshop Elements 10. When I did it the first time the photographs were all muddled up in their albums. When I tried to sync again the photographs were all removed. On the third try I received an error message something like 'Unable to sync photographs program cannot be found.' Can anyone help. (It may be to do with Windows 7 and Libraries??)
Did you already try to delete the photo cache? iTunes: Understanding the iPod Photo Cache folder
-
Please can someone help me.
When i try to work on any file in either PS or nik software the following thing happen
1) I notive the image file comes up with the reprosses message
2) I reprocess and then then try to edit file in PS or NIK and get the following
or
I read a group discussion which suggested repairing the library (middle Button) and rebout but the results were the same. Can someone please help, I am not that techie (over 65) so could I ask that any suggestion are very clear and assume that I know very little. Regards MarkI had my previous note all organised with screen grabs of the three messages I wwas talking about but the have not appeared in my post!
1) reprosses message asking to reprosses file
2)audio/video(adjustments disabled) this showed up in the adjustemnt window.
3editing error sayinh "this image cannot be rendered for editing because aperture does not support the image format"
Sorry that my screen grabs didnt work -
I just got a apple ID and an iPod touch and when I'm trying to sync it to my iTunes and try and log on it says that my apple id hasnt been used in iTunes store before and wont let me do anything...?
No iCloud account previously. Message suggests I need to give email address in account username/I'D which isn't my Apple ID which is something different to an email address?
-
AI CS 6 crashes when I try to export an image with layers to PS CS6
Hi guys!
well, I'm completely newbie on Illustrator. I only have to use it to create level on pdf images to work with it in Photoshop.
So I installed Illustrator yesterday for the first time and immediately the problems started.
Ay the first opening I had more than one error
Immediately following this (before the program started for its first time)
Then I opened a pdf file in it, select > all , Object > clipping mask > release, Layers, release to layers (Sequence).
Till here all went OK.
At this point All i nedd it's to export in Photoshop CS6.
So File > export >save as *psd.
At this point Illustrator crashes every time!
I did all the update with Adobe Application Updater, my PC is new and a really good PC.
It runs Win8 64 and with PS all goes like a charme.
What have I to do? I see many posts about the plugins problem (and still no solution by Adobe).
I ignore the problem for the plugin errors, and after some reload now I don't have that error but this one:
Same thing when I relaunch, each time and every time.
I need to solve this problem and it's impossible for me to call Adobe customer assistence As you can see my English is pretty bad and I can write but not speak by phone.
Can you guys hep me please?
Thanks in advance
LioHave you tried trashing the prefs?
-
Why when I try to login the Itunes Connect with my Apple ID it always says: "Apple ID does not have permission to access iTunes Connect."?
Look on one of your bank statements and be sure to enter the billing address exactly as it shows on the statement. Some folks forget where they actually get the statement. They put their home address in iTunes/Mac App Store and they actually get the statement at their place of employment or vice versa.
-
Why when I try to sign in to Find my Friends does it tell me I cannot as my iPhone is not supported with free iCloud service? I do not use find my friends on another device.
So, have you created an iCloud account and is your device connected to iCloud?
-
Why when I try to log in using my Apple ID that it comes up as incorrect even though I know it isn't. After several attempts I was asked to select a new password after correctly answering required security questions my new password was excepted. Guess what, when I tried to log in again using new password I received the same message telling me my ID/Password again was incorrect. I have only had this IPad a few months & this is the 3 rd time I have been forced to change the password. Can anyone tell me what I'm doing wrong.
Thanking you
JaniceIt sounds like you have a a password-protected PDF. The password was set by the person who encoded it.
-
Why when I try to download songs onto my iPhone from my iPad, it pops up and says "This device is already associated with an Apple ID, You can download past purchases on this device with just one Apple ID every 90 days. You cannot associate this device with a different Apple ID for 90 days
(Note, mine says 28 days because I have been waiting for a fair bit for this to go away.)You can't keep changing the ID you use with iTunes, you are limited to once every 90 days.
-
Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.
AMDS for Windows
http://support.apple.com/kb/TS1567 -
why, when I try to set up an exchange account for my gmail, does it keep telling me my password is wrong?
Try unlocking your account here: https://accounts.google.com/b/0/DisplayUnlockCaptcha
-
I have an iPhone 4S. When I try to print pictures, from my Windows computer, it doesn't work. Open Office also gives me an "unknown graphic" message. These are JPEGs, aren't they? Why can't I print and what is the unknown graphic?
Hi,
"A day after the name change became official my built in skydrive app stopped working"
Did you point that SkyDrive changed to OneDrive?
Did you move your OneDrive to another location or change its name?
Please login OneDrive with web-based to check if you could access it successfully.
Please refer to the following article to try the troubleshooter and check the service status:
SkyDrive: FAQ
http://windows.microsoft.com/en-in/windows-8/skydrive-app-faq
Karen Hu
TechNet Community Support -
Why when I try to subscribe to PDF converter for Word-nothing happens-have entered password & ID and
Why when I try to subscribe to PDF converter for Word - nothing happens- have entered password and email which have been verified. Please advise
House & Garden wrote:
PDF converter for Word
Not sure what you mean...
PDF to Word : ExportPDF : post in http://forums.adobe.com/community/exportpdf
Word to PDF : CreatePDF : post in http://forums.adobe.com/community/createpdf -
jsut update the adobe reader to version xi but why when I try to typing some information, no copy and paste function available?
What is your operating system?
"type some information" into where - a form field?
"no copy and paste function available" - what exactly does that mean? -
Why when I try to update certain app it require an old email address and password I have not used for years and I do I get to update them on my new details
Apps are tied to the Apple ID that was used to purchase them and you will always need to use that ID and password in order to update them.
Saying that you do get to update them on your new details makes no sense at all.
Maybe you are looking for
-
Multi-factor Authentication?
Multi-factor authentication will soon be mandatory for several of my applications. I need to know if CF has any built-in functionality, either stock or via custom tags, to handle any of the common multi-factor tools. How are other people handling thi
-
Sir/madam, I am quite new to the Labview FPGA module. I am currently working on an application where i have to generate a pwm to control the ON time duration . The pwm ON time depends on the frequency of an input signal.I want to retrieve the ON tim
-
How do I make the PS background transparent. I just want the radio to be visible in front of another graphic. TIA.
-
Lost audio control after update
Hi - My audio progress bar shows full audio image on the desktop at all times and audio can't be muted or turned down. It makes this rhythmic metronome sound, flap, flap, flap. I have my speakers hooked up so I use them to mute the sound. Mute on G5
-
What browsers can I use for mac os x 10.5.8?
Safari is updated but has not been working for the past few months and I have submitted it SO many times. I have it open for 30 seconds and it crashes EVERY time. I'm currently using a very old chrome version but I can watch any videos at all on it.