مشکل در دانلود عکس از وب سرور
سلام
من کد های زیر رو برای دانلود عکس از وب سرور نوشتم که در پوشه temp نام عکس ها رو ایجاد میکنه ولی اندازه شون صفر هستش و error زیر رو میده : (در ضمن متن ها رو از رو وب سایت میاره و در listveiw نشون میده به جز عکس)
کد من که همان کد تمیز شده استاد هستش:
public DownloadRequest download() {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
URL url = new URL(downloadPath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.connect();
totalSize = connection.getContentLength();
File file = new File(filepath);
if (file.exists()) {
file.delete();
}
FileOutputStream outputStream = new FileOutputStream(filepath);
InputStream inputStream = connection.getInputStream();
byte[] buffer = new byte[G.DOWNLOAD_BUFFER_SIZE];
int len = 0;
while ((len = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
downloadedSize += len;
percent = (int) (100.0f * (float) downloadedSize / totalSize);
if (percent == 100 && listener != null) {
G.HANDLER.post(new Runnable() {
public void run() {
listener.onDownloadComplete(downloadPath, filepath);
}
});
}
if (simulate) {
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
outputStream.close();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
});
thread.start();
return this;
}
و دستور فرستادن url هم اینه
DownloadRequest downloadRequest = new DownloadRequest()
.downloadPath(url)
.filepath(G.DIR_TEMP + "/" + filename)
.listener(downloadCompleteListener)
.download();
که error زیر رو در logcat نشون میده:
اگه دقت کنید آدرس که url هستش رو هم log کرده .
لطفا کمکم کنید
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
