/    Sign up×
Community /Pin to ProfileBookmark

PDF download Issue on mobile UC browser

Hello,

I am using springboot, while downloading pdf file by ajax call in UC mobile browser it is gives protocol not supported Error.
Can you guys let me known what is cause?

Thanks,

to post a comment

11 Comments(s)

Copy linkTweet thisAlerts:
@sushil123authorMay 28.2019 — Hello,

Any one known solution?

Thanks
Copy linkTweet thisAlerts:
@VITSUSAMay 28.2019 — Can you please show the screenshot to review the error message? It will more helpful to us to understand the exact problem.
Copy linkTweet thisAlerts:
@sushil123authorMay 28.2019 — @VITSUSA#1604090

Hi,

on UC browser when i click on download option toast comes and saying Protocol not supported.

Thanks
Copy linkTweet thisAlerts:
@sushil123authorMay 28.2019 — @sushil123#1604093

Spring boot controler code

@RequestMapping(value="/service/invoice/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)

public ResponseEntity<InputStreamResource> downloadPDF(@PathVariable String id) {

try {

ByteArrayOutputStream byteArrayOutputStream = pdfGenerationService.generatePdf(id);

if (byteArrayOutputStream != null) {

HttpHeaders headers = new HttpHeaders();

headers.add("Content-Disposition", "attachment; filename=invoice.pdf");

return ResponseEntity

.ok()

.headers(headers)

.contentType(MediaType.APPLICATION_PDF)

.contentLength(byteArrayOutputStream.size())

.body(new InputStreamResource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())));

} else

return ResponseEntity.status(404).build();

} catch (Exception e) {

LOG.error("downloadPDF", e);

}

return ResponseEntity.status(404).build();

}
Copy linkTweet thisAlerts:
@sushil123authorMay 28.2019 — @sushil123#1604096

AJAX Call code


var request = require('superagent');

request

.get(downloadPdf)

.query({ invoiceId: "123})

.responseType('blob')

.end((error, response) => {

if (!error && response) {

saveAs(response.body, "invoice");


this.setState({ isPdfDownloaded: false })

} else {

alert("error while downloading file")

}

})
Copy linkTweet thisAlerts:
@sushil123authorJun 03.2019 — Any one have idea
Copy linkTweet thisAlerts:
@PeterPan_321Jun 06.2019 — I don't use AJAX nor Springboot, ( straight javascript and PHP for me). But I can tell you my usual PHP code for downloading a file looks like this...
``<i>
</i>function downloadFile($path) {
$path_parts = pathinfo($path);
$ext = strtolower($path_parts["extension"]); // don't need this.
$fsize =fileExists($path);
if ($fsize == 0) return 0;

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: filename="" . $path_parts["basename"].""");
header("Content-Type: application/x-file-to-save");
header("Content-Transfer-Encoding: binary");
if($fsize) header("Content-length: $fsize");
$bytesRead = readfile($path);
return $bytesRead;
} <i>
</i>
``


Now if change the content type to application/octet-stream, (which looks similar to your call), even on a desktop its unpredictable. If its an MP3 or a PDF for example, firefox will try to render or play it, where Chrome will usually just download it. The 'x-file-to-save' instead will either cause download, or an alert box asking whether the user wants to "play/view" the file or save it.

But, I'll also say that I generally block calls to download a file on mobile devices, because the result is hard to control and is often useless. Remember that most (or at least ale ones I know) phone browsers don't have any "file system" to download to. So unless its a file type the browser can directly deal with (many can display PDFs), the end result becomes difficult to predict.

On the client side web page, I'll usually call a PHP file containing my script with an XMLHttprequest, formating the script string with all the parameters I need to pass (in this case a file). Don't know if any of this helps, as I'm not using your platforms
Copy linkTweet thisAlerts:
@sushil123authorJun 08.2019 — @PeterPan_321#1604405

Okay,

Thanks, for replay.
Copy linkTweet thisAlerts:
@onelastchanceJun 10.2019 — Is springboot good?
Copy linkTweet thisAlerts:
@keithlarsonNov 24.2019 — I've has a similar issue and I downloaded the older version of UC browser from https://freewindows10.download/soft/uc-browser and I do not update it. It helped me. Maybe try to reinstall the software. Or you can change to another browser but I do not know which one is compatible with springboot.
Copy linkTweet thisAlerts:
@mary099Nov 25.2019 — > @sushil123#1604096 Spring boot controler code
>
> @RequestMapping(value="/service/invoice/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)

> public ResponseEntity<InputStreamResource> downloadPDF(@PathVariable String id) {

> try {

> ByteArrayOutputStream byteArrayOutputStream = pdfGenerationService.generatePdf(id);

> if (byteArrayOutputStream != null) {

> HttpHeaders headers = new HttpHeaders();

> headers.add("Content-Disposition", "attachment; filename=invoice.pdf");

> return ResponseEntity

> .ok()

> .headers(headers)

> .contentType(MediaType.APPLICATION_PDF)

> .contentLength(byteArrayOutputStream.size())

> .body(new InputStreamResource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())));

} els [url=http://http://www.ork.tn/]chercheremploientunisie[/url]

> return ResponseEntity.status(404).build();

> } catch (Exception e) {

> LOG.error("downloadPDF", e);

> }

> return ResponseEntity.status(404).build();


Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".

We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
×

Success!

Help @sushil123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...