Upload Image from Gallery to FTP No such file or directory2019 Community Moderator ElectionHow do I create a Java string from the contents of a file?How to upload files to server using JSP/Servlet?Is there a way to get the source code from an APK file?How to send image from one activity to another in android?android FTPClient cannot upload file - FTP response 421 received. Server closed connectionconverting string path to inputstreamFile restrictions in android Nougatimage view by using image buttonAndroid: Multiple image viewE/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException for (No such file or directory)
What do you call someone who likes to pick fights?
Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?
Does the US political system, in principle, allow for a no-party system?
Under what conditions can the right to be silence be revoked in the USA?
Doublet with ladder line vs coax w.r.t. noise
Is there a way to make cleveref distinguish two environments with the same counter?
Why restrict private health insurance?
When an outsider describes family relationships, which point of view are they using?
How can I portion out frozen cookie dough?
How to increase the accuracy of a plot
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
The (Easy) Road to Code
Finding the minimum value of a function without using Calculus
Does an unused member variable take up memory?
Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?
How do I increase the number of TTY consoles?
Why aren't there more Gauls like Obelix?
Is there a logarithm base for which the logarithm becomes an identity function?
Optimal Proportions for Flying Humans
Locked Away- What am I?
Which country has more?
Are these two graphs isomorphic? Why/Why not?
Do Paladin Auras of Differing Oaths Stack?
What does the Digital Threat scope actually do?
Upload Image from Gallery to FTP No such file or directory
2019 Community Moderator ElectionHow do I create a Java string from the contents of a file?How to upload files to server using JSP/Servlet?Is there a way to get the source code from an APK file?How to send image from one activity to another in android?android FTPClient cannot upload file - FTP response 421 received. Server closed connectionconverting string path to inputstreamFile restrictions in android Nougatimage view by using image buttonAndroid: Multiple image viewE/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException for (No such file or directory)
I am trying to upload an image selected from the gallery to my ftp server.
My code:
public void imageButton()
chooseImg.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
System.out.println("GETTING HERE");
startActivityForResult(gallery, RESULT_LOAD_IMAGE);
);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null)
Toast.makeText(AddProduct.this, "Image selected", Toast.LENGTH_LONG).show();
Uri selected = data.getData();
new uploadFTP().execute(selected.getPath());
class uploadFTP extends AsyncTask<String, Void, String>
@Override
protected String doInBackground(String... strings)
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(InetAddress.getByName("address"));
ftpClient.login("hostname", "passowrd");
ftpClient.enterLocalActiveMode();
if (ftpClient.isConnected())
System.out.println("Connected to FTP");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
String testName = "/public_html/" + System.currentTimeMillis() + "test";
File file = new File(Arrays.deepToString(strings));
FileInputStream fis = new FileInputStream(file);
ftpClient.storeFile(testName,fis);
System.out.println("Successful");
catch (IOException e)
e.printStackTrace();
return null;
When I run this code, I get:
I/System.out: Connected to FTP
W/System.err: java.io.FileNotFoundException: [/external/images/media/217] (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:150)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:147)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:130)
at android.os.AsyncTask$2.call(AsyncTask.java:345)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:257)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
So, I know my FTP connection works as I have another class which uploads text file to my ftp correctly, but now I am trying to upload an image from the gallery and I am getting an error that there is no such file or directory for the image, so I am assuming the path is wrong or something? I am unsure on how I am doing it wrong and require some advice.
java
add a comment |
I am trying to upload an image selected from the gallery to my ftp server.
My code:
public void imageButton()
chooseImg.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
System.out.println("GETTING HERE");
startActivityForResult(gallery, RESULT_LOAD_IMAGE);
);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null)
Toast.makeText(AddProduct.this, "Image selected", Toast.LENGTH_LONG).show();
Uri selected = data.getData();
new uploadFTP().execute(selected.getPath());
class uploadFTP extends AsyncTask<String, Void, String>
@Override
protected String doInBackground(String... strings)
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(InetAddress.getByName("address"));
ftpClient.login("hostname", "passowrd");
ftpClient.enterLocalActiveMode();
if (ftpClient.isConnected())
System.out.println("Connected to FTP");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
String testName = "/public_html/" + System.currentTimeMillis() + "test";
File file = new File(Arrays.deepToString(strings));
FileInputStream fis = new FileInputStream(file);
ftpClient.storeFile(testName,fis);
System.out.println("Successful");
catch (IOException e)
e.printStackTrace();
return null;
When I run this code, I get:
I/System.out: Connected to FTP
W/System.err: java.io.FileNotFoundException: [/external/images/media/217] (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:150)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:147)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:130)
at android.os.AsyncTask$2.call(AsyncTask.java:345)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:257)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
So, I know my FTP connection works as I have another class which uploads text file to my ftp correctly, but now I am trying to upload an image from the gallery and I am getting an error that there is no such file or directory for the image, so I am assuming the path is wrong or something? I am unsure on how I am doing it wrong and require some advice.
java
add a comment |
I am trying to upload an image selected from the gallery to my ftp server.
My code:
public void imageButton()
chooseImg.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
System.out.println("GETTING HERE");
startActivityForResult(gallery, RESULT_LOAD_IMAGE);
);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null)
Toast.makeText(AddProduct.this, "Image selected", Toast.LENGTH_LONG).show();
Uri selected = data.getData();
new uploadFTP().execute(selected.getPath());
class uploadFTP extends AsyncTask<String, Void, String>
@Override
protected String doInBackground(String... strings)
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(InetAddress.getByName("address"));
ftpClient.login("hostname", "passowrd");
ftpClient.enterLocalActiveMode();
if (ftpClient.isConnected())
System.out.println("Connected to FTP");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
String testName = "/public_html/" + System.currentTimeMillis() + "test";
File file = new File(Arrays.deepToString(strings));
FileInputStream fis = new FileInputStream(file);
ftpClient.storeFile(testName,fis);
System.out.println("Successful");
catch (IOException e)
e.printStackTrace();
return null;
When I run this code, I get:
I/System.out: Connected to FTP
W/System.err: java.io.FileNotFoundException: [/external/images/media/217] (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:150)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:147)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:130)
at android.os.AsyncTask$2.call(AsyncTask.java:345)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:257)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
So, I know my FTP connection works as I have another class which uploads text file to my ftp correctly, but now I am trying to upload an image from the gallery and I am getting an error that there is no such file or directory for the image, so I am assuming the path is wrong or something? I am unsure on how I am doing it wrong and require some advice.
java
I am trying to upload an image selected from the gallery to my ftp server.
My code:
public void imageButton()
chooseImg.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
System.out.println("GETTING HERE");
startActivityForResult(gallery, RESULT_LOAD_IMAGE);
);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null)
Toast.makeText(AddProduct.this, "Image selected", Toast.LENGTH_LONG).show();
Uri selected = data.getData();
new uploadFTP().execute(selected.getPath());
class uploadFTP extends AsyncTask<String, Void, String>
@Override
protected String doInBackground(String... strings)
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(InetAddress.getByName("address"));
ftpClient.login("hostname", "passowrd");
ftpClient.enterLocalActiveMode();
if (ftpClient.isConnected())
System.out.println("Connected to FTP");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
String testName = "/public_html/" + System.currentTimeMillis() + "test";
File file = new File(Arrays.deepToString(strings));
FileInputStream fis = new FileInputStream(file);
ftpClient.storeFile(testName,fis);
System.out.println("Successful");
catch (IOException e)
e.printStackTrace();
return null;
When I run this code, I get:
I/System.out: Connected to FTP
W/System.err: java.io.FileNotFoundException: [/external/images/media/217] (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:150)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:147)
at com.example.ufaza.androidsqlitesearch.AddProduct$uploadFTP.doInBackground(AddProduct.java:130)
at android.os.AsyncTask$2.call(AsyncTask.java:345)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:257)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
So, I know my FTP connection works as I have another class which uploads text file to my ftp correctly, but now I am trying to upload an image from the gallery and I am getting an error that there is no such file or directory for the image, so I am assuming the path is wrong or something? I am unsure on how I am doing it wrong and require some advice.
java
java
asked Mar 6 at 13:35
JameshGongJameshGong
566
566
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
A Uri is not a file.
If the scheme of the Uri is file, then it represents a file on the filesystem that, in theory, your app should be able to access. Use getPath() to get the filesystem path.
If the scheme is anything else, it does not necessarily represent a file on the filesystem that your app can access. For example, if the scheme is http or https, the Uri represents something that would be downloaded from a Web server.
If the scheme is content, then it is backed by a ContentProvider. Use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri.
So I should do::InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just doftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?
– JameshGong
Mar 6 at 14:13
@JameshGong: I have no idea ifftpClient.storeFile()supports anInputStream. FTP is horribly insecure; nobody should be using it.
– CommonsWare
Mar 6 at 14:19
add a comment |
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024405%2fupload-image-from-gallery-to-ftp-no-such-file-or-directory%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
A Uri is not a file.
If the scheme of the Uri is file, then it represents a file on the filesystem that, in theory, your app should be able to access. Use getPath() to get the filesystem path.
If the scheme is anything else, it does not necessarily represent a file on the filesystem that your app can access. For example, if the scheme is http or https, the Uri represents something that would be downloaded from a Web server.
If the scheme is content, then it is backed by a ContentProvider. Use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri.
So I should do::InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just doftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?
– JameshGong
Mar 6 at 14:13
@JameshGong: I have no idea ifftpClient.storeFile()supports anInputStream. FTP is horribly insecure; nobody should be using it.
– CommonsWare
Mar 6 at 14:19
add a comment |
A Uri is not a file.
If the scheme of the Uri is file, then it represents a file on the filesystem that, in theory, your app should be able to access. Use getPath() to get the filesystem path.
If the scheme is anything else, it does not necessarily represent a file on the filesystem that your app can access. For example, if the scheme is http or https, the Uri represents something that would be downloaded from a Web server.
If the scheme is content, then it is backed by a ContentProvider. Use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri.
So I should do::InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just doftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?
– JameshGong
Mar 6 at 14:13
@JameshGong: I have no idea ifftpClient.storeFile()supports anInputStream. FTP is horribly insecure; nobody should be using it.
– CommonsWare
Mar 6 at 14:19
add a comment |
A Uri is not a file.
If the scheme of the Uri is file, then it represents a file on the filesystem that, in theory, your app should be able to access. Use getPath() to get the filesystem path.
If the scheme is anything else, it does not necessarily represent a file on the filesystem that your app can access. For example, if the scheme is http or https, the Uri represents something that would be downloaded from a Web server.
If the scheme is content, then it is backed by a ContentProvider. Use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri.
A Uri is not a file.
If the scheme of the Uri is file, then it represents a file on the filesystem that, in theory, your app should be able to access. Use getPath() to get the filesystem path.
If the scheme is anything else, it does not necessarily represent a file on the filesystem that your app can access. For example, if the scheme is http or https, the Uri represents something that would be downloaded from a Web server.
If the scheme is content, then it is backed by a ContentProvider. Use a ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri.
answered Mar 6 at 13:46
CommonsWareCommonsWare
776k13918921938
776k13918921938
So I should do::InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just doftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?
– JameshGong
Mar 6 at 14:13
@JameshGong: I have no idea ifftpClient.storeFile()supports anInputStream. FTP is horribly insecure; nobody should be using it.
– CommonsWare
Mar 6 at 14:19
add a comment |
So I should do::InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just doftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?
– JameshGong
Mar 6 at 14:13
@JameshGong: I have no idea ifftpClient.storeFile()supports anInputStream. FTP is horribly insecure; nobody should be using it.
– CommonsWare
Mar 6 at 14:19
So I should do::
InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just do ftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?– JameshGong
Mar 6 at 14:13
So I should do::
InputStream inputStream = getContentResolver().openInputStream(uri); and then should I then just do ftpClient.storeFile(testName,inputStream)` ? I did this and it says No Content provider am I still doing something wrong?– JameshGong
Mar 6 at 14:13
@JameshGong: I have no idea if
ftpClient.storeFile() supports an InputStream. FTP is horribly insecure; nobody should be using it.– CommonsWare
Mar 6 at 14:19
@JameshGong: I have no idea if
ftpClient.storeFile() supports an InputStream. FTP is horribly insecure; nobody should be using it.– CommonsWare
Mar 6 at 14:19
add a comment |
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.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024405%2fupload-image-from-gallery-to-ftp-no-such-file-or-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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