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

Image within PFFile will be uploaded to parse instead of being saved into the local datastorage

我正在使用 swift 和 Parse Framework (1.6.2)。我正在将数据存储到本地数据存储中。数据由几个字符串和一个图像组成。此图像将存储在 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()

好的,看这里。 可以肯定的是,如果您在 PFFile 上调用保存,它将保存到在线数据存储区。所以你应该使用 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 doc 它没有一个 .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.