How to send a file to a REST service?
up vote
0
down vote
favorite
I want to get file in rest service from android. In my code i send filestream
from android via url
. If i use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK)
Uri content_describer = data.getData();
String src = null;
try
src = getFilePath(UploadActivity.this, content_describer);
catch (URISyntaxException e)
e.printStackTrace();
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
try
FileOpen.openFile(UploadActivity.this, source);
catch (IOException e)
e.printStackTrace();
);
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item)
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton)
new Save().execute();
return true;
return super.onOptionsItemSelected(item);
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String>
protected void onPreExecute()
super.onPreExecute();
@Override
protected String doInBackground(String... params)
try
fis=new FileInputStream(source);
catch (FileNotFoundException e)
e.printStackTrace();
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
System.out.println(s);
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function
android rest file
add a comment |
up vote
0
down vote
favorite
I want to get file in rest service from android. In my code i send filestream
from android via url
. If i use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK)
Uri content_describer = data.getData();
String src = null;
try
src = getFilePath(UploadActivity.this, content_describer);
catch (URISyntaxException e)
e.printStackTrace();
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
try
FileOpen.openFile(UploadActivity.this, source);
catch (IOException e)
e.printStackTrace();
);
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item)
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton)
new Save().execute();
return true;
return super.onOptionsItemSelected(item);
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String>
protected void onPreExecute()
super.onPreExecute();
@Override
protected String doInBackground(String... params)
try
fis=new FileInputStream(source);
catch (FileNotFoundException e)
e.printStackTrace();
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
System.out.println(s);
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function
android rest file
You need to upload the file and just receive the uploaded data on Rest API, and if this data is too long you may have to upload by parts,
– Khaled Lela
yesterday
What is the data type stored on this file path, Is it image, archived or text data.
– Khaled Lela
yesterday
All mime type it supports .I select file from my mobile which may be media/* or text/* or application/* and I will click save button in my action bar which should take my file from android to rest where I will store my file in specific path of any drivers.
– Seyed Ali Fathima
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to get file in rest service from android. In my code i send filestream
from android via url
. If i use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK)
Uri content_describer = data.getData();
String src = null;
try
src = getFilePath(UploadActivity.this, content_describer);
catch (URISyntaxException e)
e.printStackTrace();
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
try
FileOpen.openFile(UploadActivity.this, source);
catch (IOException e)
e.printStackTrace();
);
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item)
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton)
new Save().execute();
return true;
return super.onOptionsItemSelected(item);
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String>
protected void onPreExecute()
super.onPreExecute();
@Override
protected String doInBackground(String... params)
try
fis=new FileInputStream(source);
catch (FileNotFoundException e)
e.printStackTrace();
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
System.out.println(s);
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function
android rest file
I want to get file in rest service from android. In my code i send filestream
from android via url
. If i use like this My entire app is not working by saying...
Logcat
Operation
Fileacces
in contract 'IREST' has a query variable named
stream
of typeSystem.IO.FileStream
, but type
System.IO.FileStream
is not convertible byQueryStringConverter
.
Variables for UriTemplate query values must have types that can
be converted byQueryStringConverter
Here I have post my coding FYR
public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK)
Uri content_describer = data.getData();
String src = null;
try
src = getFilePath(UploadActivity.this, content_describer);
catch (URISyntaxException e)
e.printStackTrace();
Log.d("src is: ", src);
source = new File(src);
fname = source.getName();
Button text = (Button) findViewById(R.id.txt);
text.setText(fname);
text.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
try
FileOpen.openFile(UploadActivity.this, source);
catch (IOException e)
e.printStackTrace();
);
Onclick event in action bar icon:
@Override
public boolean onOptionsItemSelected(MenuItem item)
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.mybutton)
new Save().execute();
return true;
return super.onOptionsItemSelected(item);
SAVE function asynctask
private class Save extends AsyncTask<String,Void,String>
protected void onPreExecute()
super.onPreExecute();
@Override
protected String doInBackground(String... params)
try
fis=new FileInputStream(source);
catch (FileNotFoundException e)
e.printStackTrace();
ServiceHandler jsonParser = new ServiceHandler();
String fileaccess = ip+"Mobile/rest.svc/Fileacces?stream="+fis+"&filename="+fname;
Log.d("Fileaccess","fileaccess"+fileaccess);
String result = jsonParser.makeServiceCall(fileaccess, ServiceHandler.GET);
Log.i("fileaccess", "result: > " + result);
return null;
@Override
protected void onPostExecute(String s)
super.onPostExecute(s);
System.out.println(s);
My rest function in vb.net
Public Function fileacces(ByVal stream As FileStream, ByVal filename As String) As String Implements IREST.fileacces
Dim result = ""
Try
Dim path = "D:XXXYYYECM SourceArchiveEZECMSettingsMonitor" + filename
Dim fileStream = New FileStream(path, FileMode.Create, FileAccess.Write)
stream.CopyTo(fileStream)
fileStream.Dispose()
result = "file uploaded"
Catch ex As Exception
End Try
Return result
End Function
android rest file
android rest file
edited yesterday
Khaled Lela
2,52622046
2,52622046
asked Nov 10 at 10:32
Seyed Ali Fathima
84
84
You need to upload the file and just receive the uploaded data on Rest API, and if this data is too long you may have to upload by parts,
– Khaled Lela
yesterday
What is the data type stored on this file path, Is it image, archived or text data.
– Khaled Lela
yesterday
All mime type it supports .I select file from my mobile which may be media/* or text/* or application/* and I will click save button in my action bar which should take my file from android to rest where I will store my file in specific path of any drivers.
– Seyed Ali Fathima
yesterday
add a comment |
You need to upload the file and just receive the uploaded data on Rest API, and if this data is too long you may have to upload by parts,
– Khaled Lela
yesterday
What is the data type stored on this file path, Is it image, archived or text data.
– Khaled Lela
yesterday
All mime type it supports .I select file from my mobile which may be media/* or text/* or application/* and I will click save button in my action bar which should take my file from android to rest where I will store my file in specific path of any drivers.
– Seyed Ali Fathima
yesterday
You need to upload the file and just receive the uploaded data on Rest API, and if this data is too long you may have to upload by parts,
– Khaled Lela
yesterday
You need to upload the file and just receive the uploaded data on Rest API, and if this data is too long you may have to upload by parts,
– Khaled Lela
yesterday
What is the data type stored on this file path, Is it image, archived or text data.
– Khaled Lela
yesterday
What is the data type stored on this file path, Is it image, archived or text data.
– Khaled Lela
yesterday
All mime type it supports .I select file from my mobile which may be media/* or text/* or application/* and I will click save button in my action bar which should take my file from android to rest where I will store my file in specific path of any drivers.
– Seyed Ali Fathima
yesterday
All mime type it supports .I select file from my mobile which may be media/* or text/* or application/* and I will click save button in my action bar which should take my file from android to rest where I will store my file in specific path of any drivers.
– Seyed Ali Fathima
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath)
try
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable()
@Override
public void run()
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
);
catch (FileNotFoundException e)
e.printStackTrace();
Log.e("Error",e.toString());
catch (IOException e)
e.printStackTrace();
Log.e("Error",e.toString());
New contributor
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath)
try
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable()
@Override
public void run()
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
);
catch (FileNotFoundException e)
e.printStackTrace();
Log.e("Error",e.toString());
catch (IOException e)
e.printStackTrace();
Log.e("Error",e.toString());
New contributor
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
add a comment |
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath)
try
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable()
@Override
public void run()
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
);
catch (FileNotFoundException e)
e.printStackTrace();
Log.e("Error",e.toString());
catch (IOException e)
e.printStackTrace();
Log.e("Error",e.toString());
New contributor
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
kindly use base 64
like this
public void uploadFile(final String selectedFilePath)
try
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable()
@Override
public void run()
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
);
catch (FileNotFoundException e)
e.printStackTrace();
Log.e("Error",e.toString());
catch (IOException e)
e.printStackTrace();
Log.e("Error",e.toString());
New contributor
kindly use base 64
like this
public void uploadFile(final String selectedFilePath)
try
FileInputStream inputStream = new FileInputStream(selectedFilePath);
byte byteArray = IOUtils.toByteArray(inputStream);
final String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
getActivity().runOnUiThread(new Runnable()
@Override
public void run()
// tvFileName.setText(encoded);
Log.e("File Base 64",encoded);
filebas64=encoded;
);
catch (FileNotFoundException e)
e.printStackTrace();
Log.e("Error",e.toString());
catch (IOException e)
e.printStackTrace();
Log.e("Error",e.toString());
New contributor
New contributor
answered Nov 10 at 12:07
Vignesh Waran
11
11
New contributor
New contributor
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
add a comment |
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
Sorry I am not getting.Please tell me where to use the above function and explain me how it will work?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
try is = new FileInputStream(source); int i=0; while((i=is.read())!=-1) System.out.print((char)i); is.close(); catch (IOException e) e.printStackTrace(); ip+"Mobile/rest.svc/Fileacces?stream="+is+"&filename="+fname; how to send file stream from android and get it in my rest function?
– Seyed Ali Fathima
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238072%2fhow-to-send-a-file-to-a-rest-service%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You need to upload the file and just receive the uploaded data on Rest API, and if this data is too long you may have to upload by parts,
– Khaled Lela
yesterday
What is the data type stored on this file path, Is it image, archived or text data.
– Khaled Lela
yesterday
All mime type it supports .I select file from my mobile which may be media/* or text/* or application/* and I will click save button in my action bar which should take my file from android to rest where I will store my file in specific path of any drivers.
– Seyed Ali Fathima
yesterday