我正在尝试将多个图像上传到服务器并通过 Asynctask 将它们一张一张地发送。上传图像后,我将 URL 保存到本地列表并将其发送到 onPostExecute 中进行处理。但是,我遇到了问题,因为 onPostExecute 触发得太早并且 doInBackground 只返回空列表。
将 URI 传递给 Asynctask
new UploadImages().execute(arrayUri);
Run Code Online (Sandbox Code Playgroud)
我的异步任务
private class UploadImages extends AsyncTask<Uri,Void,List<String>>{
@Override
protected List<String> doInBackground(Uri... params) {
final ArrayList<String> urlList = new ArrayList<>();
for(Uri uri : params) {
File file = new File(uri.getPath());
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("image", file.getName(), requestBody);
RequestBody folderName = RequestBody.create(MediaType.parse("text/plain"), folder);
ApiEndpointInterface apiEndpointInterface = RetrofitManager.getApiInterface();
Call<FileInfo> call4File = apiEndpointInterface.postFile(body, folderName);
call4File.enqueue(new ApiCallback<FileInfo>() {
@Override
protected void do4Failure(Throwable t) {
Log.d(TAG, …Run Code Online (Sandbox Code Playgroud) 我对 django 真的很陌生,想知道是否有任何方法可以在带有 django 而不是另一个页面/标签的 html 模板中显示 pdf/文档的预览?
想询问任何见解。非常感谢!