0
我正在使用JCIFS SmbFileOutputStream寫入將jpg(和mp4)文件上傳到本地Windows網絡上的共享。雖然這在大多數情況下運作良好,但我有時會發現產生的文件已損壞 - 例如,如果是JPG格式,也許只有照片的頂部可以清晰可見。SmbFileOutputStream寫入創建損壞的JPG文件
我有一個try/catch塊上傳,但它沒有拋出異常。有什麼方法可以驗證文件是否已正確上傳?
try {
if (debugging_on) {
logger.info("UploadService.011 UploadFiles: uploading file:" + destFileName);
}
SmbFileOutputStream sfos = new SmbFileOutputStream(sFile);
FileInputStream fileInputStream = new FileInputStream(new File(
sSourceFilePath));
byte[] buf = new byte[16 * 1024 * 1024];
int len;
while ((len = fileInputStream.read(buf)) > 0) {
sfos.write(buf, 0, len);
}
fileInputStream.close();
sfos.close();
// Update the database to include the date/time of this upload
millisStart = Calendar.getInstance().getTimeInMillis();
sql = "UPDATE upload_history SET file_uploaded_date = "
+ millisStart + " WHERE filename = '" + filename + "'";
db.execSQL(sql);
} catch (Exception e) {
mNotifyBuilder.setContentText("Upload error - check folder permissions");
mNotificationManager.notify(1, mNotifyBuilder.build());
return "WriteFailure";