Load Server URL dicom files inside Imebra in iOS? - ios

I am using https://imebra.com/ in my application, when I load a local files it reading the DICOM file and I am able to see the Image. when, I am sending Cloud url path to imebra It is showing an error and below I shared sample code.I want to send a single or multiple url to Imebra. I don't know how to proceed.
let filePath = Bundle.main.path(forResource: fileName, ofType: "dcm") // i want to send url(https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm) here
let dataSet = try ImebraCodecFactory.load(fromFile: filepath)
_ = try dataSet.getString(ImebraTagId(group: 0x10, tag: 0x10), elementNumber: 0, defaultValue: "")
_ = try dataSet.getString(ImebraTagId(group: 0x10, tag: 0x10), elementNumber: 1, defaultValue: "")
thanks in advance.

Imebra can load local DICOM files or from remote PACS (using the DIMSE protocol).
Imebra cannot load an image directly from an URL because it uses a posix call to open the local file.
To open a file from an URL you should first load the remote file. See this answer Simple Swift file download with URL to see how to load a file to a local temporary file.
Alternatively, you could load the file to a NSData object and pass its content to an Imebra Memory object, then pass to ImebraCodecFactory a StreamReader using a MemoryStreamInput.
Disclaimer: I'm the author of Imebra

Related

Render Images in document.directory in a markdown file in swift(SwiftyMarkdown)

Am using SwiftyMarkdown framework to render my .md file to have dynamic formatted data in my VC. But i am not able to load images in my document directory referenced in .md file. I can load images if they are available in Bundle.
Any other option or framework to fix this issue? I want to dynamically load images from server and save them documents directory and refer them in .md file which is also saved in same documents directory/folder. So the url of image and .md file is same.
"MyFile.md" in documents directory contains below content
Continue your walk, joining up with your original perimeter path of the item. "
In my VC viewdidload, i access the url path and load nsattributed string to my textview using SwiftyMarkdown frmaework
let url = self.getDocumentsDirectory().appendingPathComponent("MyFile.md")
if let md = SwiftyMarkdown(url: url) {
textView.attributedText = md.attributedString()
}
The formatted text is loaded but no image as its not available in my Bundle. But its saved in the same document directory as that of "MyFile.md"
Hope its clear!

Wkwebview cannot display images in html having path of library directory

I have studied similar questions but couldnot find solution.
I am using WkWebView. It renders a html from library directory so i did loadfileurl.
It has option of displaying an image, we select the image from gallery/take camera , then from image data wecreate a file in library directory and sendthe path to web .
I tried both path var/... and also appended file://
both cases image is not displaying.
Please help.
Any suggestions appreciated.
An alternative would be to encode the images as base64 strings and insert them into the HTML before rendering. You could either save the images as images or the base64 string, depending on whether you need to use them in another context.
// Get the base64 representation of the image
let image = UIImage(named: icon) // This could also be loaded from the file system
let data = image!.pngData()
let b64String = String(data: data!.base64EncodedData(), encoding: String.Encoding.utf8)!
let finalString = "data:image/png;base64," + b64String
// Insert into HTML string before rendering in webview
let myHTML = baseHTML.replacingOccurrences(of: "#PLACEHOLDER#", with: finalString)
You will need to have #PLACEHOLDER# in your HTML file at the point where you would have the path to the image.

How do I compare 2 files with the same name in iOS to check if they are copies of the same file or different files

I am using UIDocument to save a document file to the local storage sandbox in the Documents directory. I have another file in iCloud with the same name. How would I check if those two files are copies of the same document file or two different document files with the same name?
Using NSFileVersion doesn't tell me if they are the same file, just what version of the file it is.
I tried getting the resource values of the files, but the file in the local storage sandbox gives me nil as the document identifier.
Here is code using the documentIdentifier resource value:
let localFileResourceValues = try? self.document!.fileURL.resourceValues(forKeys: [URLResourceKey.documentIdentifierKey])
let iCloudFileResourceValues = try? destinationURL.resourceValues(forKeys: [URLResourceKey.documentIdentifierKey])
print("documentIdentifier", localFileResourceValues?.documentIdentifier as Any, iCloudFileResourceValues?.documentIdentifier as Any, localFileResourceValues?.documentIdentifier == iCloudFileResourceValues?.documentIdentifier)
Print results:
documentIdentifier nil Optional(133819) false
Is it possible to get an NSMetadataItem from a file in the local storage sandbox?
I would appreciate any help.
To find out if the two file paths point to the same file object, you need to normalise the file paths by using NSString stringByStandardizingPath, then resolve symbolic links by using NSString stringByResolvingSymlinksInPath:, and then compare the paths. This web page has a good description and ready-to-go code.
To find out whether two files have the same contents, even while they might be different file objects, then NSFileManager contentsEqualAtPath:andPath: is useful.

File object from URL

I'd like to create a file object from an image located at a specific url. I'm downloading the file with Net Http:
img = Net::HTTP.get_response(URI.parse('https://prium-solutions.com/wp-content/uploads/2016/11/rails-1.png'))
file = File.read(img.body)
However, I get ArgumentError: string contains null byte when trying to read the file and store in into the file variable.
How can I do this without having to store it locally ?
Since File deals with reading from storage, it's really not applicable here. The read method is expecting you to hand it a location to read from, and you're passing in binary data.
If you have a situation where you need to interface with a library that expects an object that is streaming, you can wrap the string body in a StringIO object:
file = StringIO.new(img)
# you can now call file.read, file.seek, file.rewind, etc.

downloading and storing files from given url to given path in lua

I'm new with lua but working on an application that works on specific files with given path. Now, I want to work on files that I download. Is there any lua libraries or line of codes that I can use for downloading and storing it on my computer ?
You can use the LuaSocket library and its http.request function to download using HTTP from an URL.
The function has two flavors:
Simple call: http.request('http://stackoverflow.com')
Advanced call: http.request { url = 'http://stackoverflow.com', ... }
The simple call returns 4 values - the entire content of the URL in a string, HTTP response code, headers and response line. You can then save the content to a file using the io library.
The advanced call allows you to set several parameters like HTTP method and headers. An important parameter is sink. It represents a LTN12-style sink. For storing to file, you can use sink.file:
local file = ltn12.sink.file(io.open('stackoverflow', 'w'))
http.request {
url = 'http://stackoverflow.com',
sink = file,
}

Resources