PFFile中的图像将上传到解析而不是保存到本地数据存储中 [英] Image within PFFile will be uploaded to parse instead of being saved into the local datastorage

查看:169
本文介绍了PFFile中的图像将上传到解析而不是保存到本地数据存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift与Parse Framework(1.6.2)。我将数据存储到本地数据存储区。数据由几个字符串和一个图像组成。此图像将存储在PfFile中,然后将添加到PfObject中。

I am using swift with the Parse Framework (1.6.2). I am storing data into the local datastorage. The data consists of a few strings and an image. This image will be stored within a PfFile and then will be added to the PfObject.

现在我想知道为什么图像不会被保存,直到我注意到我需要调用PFFile的save()方法。问题是图像似乎上传到Parse,我不想要。我希望它存储在本地设备上..

Now I wondered why the image doesn't get saved until I noticed I needed to call the save() method of the PFFile. Problem is that the Image then seems to be uploaded to Parse which I don't want. I want it to be stored on the local device..

有解决方案吗?

谢谢

编辑:

代码的工作原理如下:

var spot = PFObject(className: "Spot")
let imageData = UIImageJPEGRepresentation(spotModel.getPhoto(), 0.05)
let imageFile = PFFile(name:"image.jpg", data:imageData)

spotObj.setObject(spotModel.getCategory(), forKey: "category")
spotObj.setObject(imageFile, forKey: "photo")


//if I simply would do this, the PFObject will be saved into the local datastorage, but the image won't be saved
spotObj.pin()

//if I do this, the image will be saved also BUT it won't be saved into the local data storage but will be uploaded to parse
imageFile.save()
spotObj.pin()


推荐答案

好的,看一看这里最终使用PFFile(解析本地数据存储区)保存在PFObject上?
这是肯定的,如果你在PFFile上调用save,它将保存到在线数据存储区。所以你应该使用PFFile.save()。我认为最好的选择是将文件保存在某个文件夹中。本地并在PFObject中保存该路径。解析文档只是说这个

Okay, take a look here Save eventually on PFObject with PFFile (Parse Local Datastore)?. One this is for sure, if you call save on PFFile it will get save to online datastore. So you should use PFFile.save(). I think best option for you is to save the file in some folder. locally and save that path in PFObject. Parse documentation just say this

"Pinning a PFObject is recursive, just like saving, so any objects that are pointed to by the one you are pinning will also be pinned. When an object is pinned, every time you update it by fetching or saving new data, the copy in the local datastore will be updated automatically. You don't need to worry about it at all."

它递归调用主PFObject中其他对象的.pin()。但是,如果你看一下 PFFile API doc 它有一个.pin(),这意味着它不支持将PFFile保存到本地数据存储区。所以我会说你应该将它们保存在某个目录中并保存PFObject中的路径。

It recursively calls .pin() on the other objects in your main PFObject. But if you take a look at PFFile API doc it doest have a .pin() which means it doesn't support saving PFFile to local datastore. So I would say you should save them in some directory and save path in your PFObject.

更新

save:

Saves the file synchronously and sets an error if it occurs.

- (BOOL)save:(NSError **)error
Parameters
error
Pointer to an NSError that will be set if necessary.

Return Value
Returns whether the save succeeded.

这篇关于PFFile中的图像将上传到解析而不是保存到本地数据存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆