一尘不染

PFFile中的图像将被上传以进行解析,而不是保存到本地数据存储中

swift

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

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

有解决方案吗?

谢谢

编辑:

该代码如下所示:

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()

阅读 139

收藏
2020-07-07

共1个答案

一尘不染

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

"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文档,
则它没有.pin(),这意味着它不支持将PFFile保存到本地数据存储中。所以我想说您应该将它们保存在某个目录中,并将路径保存在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.
2020-07-07