Wondermoose
Wondermoose

Reputation: 311

Upload files from android to wcf

Well Ive looked for hours and hours after an answer but havent really found anything that I could use.

  1. I want to be able to send/upload files (images, videos, documents, audio) to a webservice. I want to do this from an android device (version 2.2).
  2. I need to be able to send this to a tailormade wcf for my needs, I need to send information with the file in order to verify the user who wants to upload.
  3. Also worth mentioning is I use a restful wcf .net webservice which I prefer to continue to use if possible. Atleast I need to be able to use wcf .net as webservice for the communication.

All solutions Ive seen concentrate on the android part and never on the service part. I need both. :)

Upvotes: 9

Views: 2168

Answers (2)

Sumesh B
Sumesh B

Reputation: 11

Ion.with(getActivity())
        .load(URL)        
        .setMultipartFile("upload", "image/jpeg", fileToUpload)     
        .asString()
        .setCallback(new FutureCallback<String>() {

            @Override
            public void onCompleted(Exception arg0, String result) {
                hideProgressDialog();
                if(result!=null){
                    CoreFragment.this.resultCallBack.returnResult(result.toString());
                } else {
                    showErrorToast("Error");
                }
            }
        });

and wcf is

public string upload(Stream stream)
        {
            MultipartParser parser = new MultipartParser(stream);
            if (parser.Success)
            {
                try
                {

                    string strServerpath = @"C:\IISWebsite\DOTNET\BGGTS\Files\AttendanceProof\" + parser.Filename;
                    File.WriteAllBytes(strServerpath, parser.FileContents);
                }
                catch (Exception ex)
                {
                    return "Failed";
                }          
            }
            return "Success";
        }

Upvotes: 0

larsw
larsw

Reputation: 3830

This blog post http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/ describes how you can upload files with HTTP POST - which you must use from Android if you want to upload files to a WCF service wired up with webHttpBinding.

Extra metadata can be sent as HTTP headers.

--larsw

Upvotes: 3

Related Questions