CocoaMarkdown icon indicating copy to clipboard operation
CocoaMarkdown copied to clipboard

Supporting URLRequest in inline image download

Open rizwan95 opened this issue 5 years ago • 11 comments

Hi, is there any way to add URLRequest in the inline image download method? @indragiek

rizwan95 avatar Feb 26 '20 18:02 rizwan95

Hi @rizwan95, Currently the image download is handled by a simple download task and only a base URL can be configured (typically for images using relative links).

Could you provide more information about your use case, and about the type of URLRequest customization you would need?

jlj avatar Feb 26 '20 22:02 jlj

@jlj Sometimes we might need to send additional headers like user-agent and authorization headers for downloading images from authenticated services. So, it would be very helpful if there is a way to send them.

rizwan95 avatar Feb 27 '20 03:02 rizwan95

@jlj Any update on this?

rizwan95 avatar Mar 17 '20 10:03 rizwan95

A possible option could be to add a imageURLSession property of type NSURLSession in CMAttributedStringRenderer. If set, this imageURLSession property would then be used to retrieve every remote image referenced by the current document.

At creation time, the imageURLSession property could receive any desired NSURLSessionConfiguration, providing thus a high level of customizability to image download.

@rizwan95 Would this solution respond to your needs?

jlj avatar Mar 19 '20 10:03 jlj

@jlj : Yes, that would solve the problem! Infact it will open up a lot of opportunities for customizability.

rizwan95 avatar Mar 20 '20 04:03 rizwan95

@rizwan95 I have implemented this imageURLSession property change in my CocoaMarkdown fork at https://github.com/jlj/CocoaMarkdown/tree/5512cf52d292288e1748e7bde097e5b28a7e52b6

Can you test it with your specific server configuration? If it is ok, I will issue a pull request.

jlj avatar Mar 20 '20 10:03 jlj

@jlj Yes sure!

rizwan95 avatar Mar 20 '20 11:03 rizwan95

@rizwan95 Have you made tests of this imageURLSession property?

jlj avatar Apr 02 '20 15:04 jlj

Not yet, I will test it today and let you know @jlj Sorry for the delay!

rizwan95 avatar Apr 03 '20 07:04 rizwan95

@rizwan95 Any test result?

jlj avatar Apr 16 '20 12:04 jlj

Hi @jlj I tested the given patch. It is not rendering basic markdown content itself. :( I suppose something is broken..

rizwan95 avatar Oct 01 '20 13:10 rizwan95