我允许用户通过拖放和其他方法将图像加载到页面中.删除图像时,我正在使用URL.createObjectURL转换为对象URL来显示图像.我没有撤销网址,因为我重复使用它.
所以,当谈到时间来创建一个FormData对象,所以我可以让他们上传的形式,在它的形象之一,是有一些方法,然后我可以扭转这一目标URL回一个Blob或File因此我可以将其添加到FormData宾语?
给定base64输入,我如何将其转换为Android中的PDF文件?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
setContentView(R.layout.activity_main);
// Get the PDF file to encode it into Base64
File file = new File("/mnt/sdcard/download/Base64.pdf");
try {
// Files is from Guava library
Files.toByteArray(file);
// Encoded into Base64
byte[] temp = Base64.encode(Files.toByteArray(file), Base64.DEFAULT);
// For testing purposes, wrote the encoded string to file
writeToFile(Base64.encodeToString(temp, Base64.DEFAULT).toString());
} catch (IOException e) {
Log.d(tag, "File.toByteArray() error");
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我能够使用http://www.webutils.pl/index.php?idx=base64来测试PDF文件是否正确编码.但我希望能够自己将base64解码为PDF.我该怎么办?
编辑1
按照Saneesh CS的建议尝试以下代码
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) 经过很长一段时间,我使用了WebView.那么让我问一下我的阶段问题.
- 我有谷歌,Blob URL但我找到了解决方案或任何提示,所以我必须在这里发布问题.
- 我WebView在Android端加载一个网站.在他们的按钮上"SAVE-AS" to download an image.
- 当我尝试它 Google Chrome app是的它working fine并正确下载.
- webview在我的应用程序中DownloadListener
我使用Blob URL的情况相同
blob:http://-----cantshare-----.com/7e7452c8-62ca-4231-8640-0e9de715e073
下载手册 download nothing
检查我的代码
webview = (WebView) findViewById(R.id.webview);
WebSettings settings = webview.getSettings();
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
final ProgressDialog progressBar = ProgressDialog.show(this, "WebView Example", "Loading...");
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processing webview url click...");
view.loadUrl(url); …Run Code Online (Sandbox Code Playgroud) 我有一个服务器在浏览器上创建一个对象blob,我想在Android应用程序的WebView中下载它.我尝试将请求重定向到浏览器实例以及使用下载管理器执行此操作,但它们似乎都不起作用(即使我在Chrome中打开相同的页面,下载操作也在那里工作).
我尝试了以下代码,它抛出错误:
Android.content.ActivityNotFoundException:找不到处理Intent的活动{act = android.intent.action.VIEW dat = blob:https%3A // 111.111.111.111%3A8080/40b63131-63b1-4fa4-9451-c6297bbd111a"
编辑
Android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = android.intent.action.VIEW dat = blob:http://digitalinsensu.com/0f0d6127-a0f1-44c3-af85-72f648258d6d
码:
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype,long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
Run Code Online (Sandbox Code Playgroud)
这会抛出java.lang.IllegalArgumentException:只能下载HTTP/HTTPS URIs错误:
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype,long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
}
});
Run Code Online (Sandbox Code Playgroud)
我该如何下载blob?任何帮助,将不胜感激.
我正在尝试使用flutter从网站下载文件,我首先使用了evaluateJavaScript并在单击生成按钮之前更改了一些值,该按钮应该将适当的pdf文件下载到手机。
这是我的代码:
InAppWebView(
initialUrl: '...',
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
useOnDownloadStart: true,
javaScriptEnabled: true,
),
),
//javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (InAppWebViewController webViewController) {
_controller = webViewController;
},
onLoadStop: (_controller ,url) async {
await _loadData();
_controller.evaluateJavascript(source:
"console.log(document.getElementById('field-lastname').value = '${data[Field.name]}' );"
+"console.log(document.getElementById('generate-btn').click());"
);
},
onDownloadStart:(_controller,url) async{
print("onDownloadStart $url");
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: (await getExternalStorageDirectory()).path,
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true,);
},
),
Run Code Online (Sandbox Code Playgroud)
打印出来的网址是这样的
onDownloadStart blob:https://example.com/a2a5316c-9290-4da7-8a2a-9f899861046a
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?
我想从 webview 下载文件,但每次都会出错(只能下载 HTTP/HTTPS URI:blob: https://..)
我在我的代码中使用这个:
ngOnInit() {
let webview: WebView = this.webViewRef.nativeElement;
if (isAndroid) {
webview.on(WebView.loadStartedEvent, function () {
webview.android.getSettings().setBuiltInZoomControls(false);
webview.android.getSettings().setJavaScriptEnabled(true);
webview.android.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.android.getSettings().setAllowFileAccess(true);
webview.android.getSettings().setPluginsEnabled(true);
webview.android.getSettings().setAllowContentAccess(true);
webview.android.getSettings().setAllowFileAccess(true);
webview.android.getSettings().setAllowFileAccessFromFileURLs(true);
webview.android.getSettings().setAllowUniversalAccessFromFileURLs(true);
webview.android.getSettings().setDomStorageEnabled(true);
webview.android.getSettings().setDefaultTextEncodingName("utf-8");
webview.android.setDownloadListener(new android.webkit.DownloadListener({
onDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength) {
let request = new android.app.DownloadManager.Request(android.net.Uri.parse(url));
request.setMimeType(mimetype);
let cookies = android.webkit.CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(android.webkit.URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(android.os.Environment.DIRECTORY_DOWNLOADS, android.webkit.URLUtil.guessFileName(url, contentDisposition, mimetype));
let dm = utils.ad.getApplicationContext().getSystemService(android.content.Context.DOWNLOAD_SERVICE);
dm.enqueue(request);
}
}));
});
}
Run Code Online (Sandbox Code Playgroud)
请帮助我。谢谢