I'm having a hard time passing files with spaces in their names into Twilio
chat.
Forgetting about the fact that I'm using Twilio, and just concentrating that I'm trying to upload a file from within the Android phone. I have an image on my android phone which I found its path as /Internal storage/Download/4893079.jpg
Below is the full code:
public void testing() {
Messages messagesObject = channel.getMessages();
try {
messagesObject.sendMessage(
Message.options()
.withMedia(new FileInputStream("/Internal%20storage/Download/4893079.jpg"), "image/jpeg")
.withMediaFileName("4893079.jpg")
.withMediaProgressListener(new ProgressListener() {
@Override
public void onStarted() {
System.out.println("Upload started");
}
@Override
public void onProgress(long bytes) {
System.out.println("Uploaded " + bytes + " bytes");
}
@Override
public void onCompleted(String mediaSid) {
System.out.println("Upload completed");
}
}),
new CallbackListener<Message>() {
@Override
public void onSuccess(Message msg) {
System.out.println("Successfully sent MEDIA message");
}
@Override
public void onError(ErrorInfo error) {
System.out.println("Error sending MEDIA message");
}
});
} catch (FileNotFoundException e) {
System.out.println("FAILED HORRIBLY");
System.out.println(e);
e.printStackTrace();
}
}
However running the app I end up with the error,
java.io.FileNotFoundException: /Internal%20storage/Download/4893079.jpg (No such file or directory)
As shown I've tried replacing space with %20
, but that didn't work. I've also tried \
, \\
. However non of them worked. I've looked at Opening a local Android File with spaces, Save file in Android with spaces in file name.
How should I be replacing the space?