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

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

问题描述

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

有没有办法解决这个问题?

Is there a solution for this?

谢谢

代码如下:

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天全站免登陆