Saving CKAsset from Core Data - swift

I have some data like pictures, stored in Core Data as binary data and marked as "Allows External Storage". I'd like to write this data to the CloudKit. Is it possible to get URLs for this data and pass it to CKAsset, or transform somehow this data to CKAsset without double writing this data to some temporary files? Thank you.

Accessing external binary data directly is not supported and there's no API for it. Unofficially it's not hard to figure out what directory the files are stored in, but it's not useful because
Filenames are UUIDs, and there's no documented way to link a managed object to a UUID, so you don't know which file to use.
The option is to allow external storage, so there's no guarantee that an external file exists. Some instances may not use external storage.
I'm not sure what CKAsset requires but you'll have to look up the binary data via the managed object first.

Related

Google Cloud Storage Python API: blob rename, where is copy_to

I am trying to rename a blob (which can be quite large) after having uploaded them to a temporary location in the bucket.
Reading the documentation it says:
Warning: This method will first duplicate the data and then delete the old blob. This means that with very large objects renaming could be a very (temporarily) costly or a very slow operation. If you need more control over the copy and deletion, instead use google.cloud.storage.blob.Blob.copy_to and google.cloud.storage.blob.Blob.delete directly.
But I can find absolutely no reference to copy_to anywhere in the SDK (or elsewhere really).
Is there any way to rename a blob from A to B without the SDK copying the file. In my case overwriting B, but I can remove B first if it's easier.
The reason is checksum validation, I'll upload it under A first to make sure it's successfully uploaded (and doesn't trigger DataCorruption) and only then replace B (the live object)
GCS itself does not support renaming objects. Renaming with a copy+delete is done in the client as a helper, and there is no better way to rename an object at the moment.
As you say your goal is checksum validation, there is a better solution. Upload directly to your destination and use GCS's built in checksum verification. How you do this depends on the API:
JSON objects.insert: Set crc32c or md5Hash header.
XML PUT object: Set x-goog-hash header.
Python SDK Blob.upload_from_* methods: Set checksum="crc32c" or checksum="md5" method parameter.

How to send emails with attachments located on disc using PL/SQL?

I have a ready script which sends email using PL/SQL. It has been stored in a procedure and when it is called by passing proper parameters, it sends email.
Now, I need to pick up a file from the disc and send it as an attachment. I have seen many examples where the data is stored in BLOB and comes from the DB. In my case it is not from DB instead it is a file on the server/disc.
How to achieve this ?
Use UTL_FILE to read data from disk.
You can find a good example of how to use it to load an entire file into a BLOB in the Alexandria PL/SQL Library. Look at (or just copy!) the code from file_util_pkg.get_blob_from_file.
ORACLE DIRECTORIES can be used to achieve this.
link to a full email/smtp example

Store gif in Core Data - Swift 3

How can I store a GIF image fetched from HTTP request in Core Data?
I already store my still images with UIImagePNGRepresentation as NSData in a Binary data attribute, but I have how to proceed with a gif?
Edit: What I've done so far is getting the data from the request, then storing it in the BinaryData using UIImagePNGRepresentation. But when I try to create a UIImage with SwiftyGif, an error message shows up saying Could not determine delay times for GIF. So I guess the PNG representation mess with the frames of the GIF.
I also tried to directly store the data from the http request but then the UIView throw me this error: Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN
A gif is a file format, and files are data and data can be stored in core data. Nevertheless it s a bad practice to store large amount of binary data in any database, and a filesystem is often a better choice. I would recommend storing the files in the file system and keeping relative file path in the database (make sure it is relative, because the app's container directory can change). If these are images that are retrieve from a server and can be refetched they should be stored in the tmp directory (or should just be managed separately with something like SDWebImage). If they are not retrievable later then they should be stored in the documents directory.
If that seems to hard then you can still store them in core-data. Core-data does has an option to allow it to store property as files outside of the database file ("Allows External Storage").
When you call UIImagePNGRepresentation, you're converting PNG data to a Swift Data structure. If you save it in Core Data, you'll be using a binary attribute.
You didn't mention how you're storing your GIFs. If you have them in Data instances then you do it exactly as with the PNGs-- with a Core Data binary attribute. If you have something other than a Data, please explain what kind of object or struct you're using to hold the GIF data.

Trouble working with nested JSON objects on Objective-C

On my iPhone app, I'm getting this response from the server:
I need to save this data to disk, so it can be accessed while offline, and am doing it with NSKeyedArchiver.
I need to save each id_preguntawith its correspondent values, including the array respuestas, which has some objects, too.
How can I break this server response into more manageable data, so I can save it? My current approach is using NSMutableDictionary, but I just can't understand the logic behind this (I'm way too tired).
Thanks in advance.
If you were to serialize this into NSMutableDictionary you could just write the contents of the dictionary to a file. If you need to parse the data into objects (for whatever reason) or you want the general scalability and performance of a database you may want to look at this link to -> Core Data.
However; you did not specify in what form you want the data.
Frank
See these in NSDictionary class reference...
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
and
+ (id)dictionaryWithContentsOfFile:(NSString *)path`

Google Cloud Storage : Can we Get file or Search file based on meta data?

While Uploading Object , I have assigned metadata using x-goog-meta-<keyname>.
Currently to get file , we have to use Get Object using Key/Filename.
I want know is it possible like Get Object using META-DATA ?
Is there any way we can directly get/search file by passing metadata ?
Thanks!
No, you cannot.
You can retrieve the metadata via the object name, but you cannot retrieve the object name via the metadata.
If you really needed to, you could create a second bucket that contained objects with the metadata names with data or metadata that referred to the original object name in the first bucket.