- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么我用 iPhone 拍摄的一些照片太大而无法上传到 PFFile 进行解析。限制是 10 mgb,我知道这些图片不可能那么大。有些足够小,但大多数还不够。有没有办法优化解析的大小?这是我的代码
//--CONTROLS HOW TO PICK THE IMAGE WHEN THIS BUTTON IS CLICKED--\\
@IBAction func chooseImage(sender: AnyObject) {
var image = UIImagePickerController()
image.delegate = self
image.navigationBar.tintColor = UIColor.whiteColor()
image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
image.allowsEditing = false
self.presentViewController(image, animated: true, completion: nil)
}
@IBAction func postImage(sender: AnyObject) {
self.view.endEditing(true)
var error = ""
if photoSelected == false{
error="Please select an image to post."
}
else if contactText.text == ""{
error = "Please enter an email or phone number."
}
else if nameOfPost.text == ""{
error="Please enter the name of the post."
}
else if descriptionOfPost.text == ""{
error="Please enter a description about your posts."
}
if error != ""{
displayAlert("Oops! There was an error with posting.", error: error)
}
else{
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 125, 125))
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
activityIndicator.backgroundColor = UIColor(red: (158/255.0), green: (40/255.0), blue: (52/255.0), alpha: 1)
activityIndicator.layer.cornerRadius = 10
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
//--MAIN CODE TO POST--\\
var post = PFObject(className: "Posts")
post["Contact"] = contactText.text
post["Name"] = nameOfPost.text
post["Description"] = descriptionOfPost.text
let imageData = UIImagePNGRepresentation(self.imageToPost.image)
let imageFile = PFFile(name: "image.png", data: imageData)
post["imageFile"] = imageFile
post["createdBy"] = PFUser.currentUser()?.objectId
//--GETTING LOCATION OF THE POST--\\
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, error: NSError?) -> Void in
if error == nil {
post.setValue(geoPoint, forKey: "Location")
post.saveInBackground()
println("found location")
}
}
//--SAVING THE Post HERE--\\
post.saveInBackgroundWithBlock{(success:Bool, error:NSError?)-> Void in
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if success == false{
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
self.displayAlert("Sorry! We could not post.", error: "Please try again later.")
}
//--NO ERRORS SO NOW WE CAN SAVE AND POST==\\
else{
self.performSegueWithIdentifier("backToFeed", sender: self)
}
}
}
}
我确实需要能够为我的应用程序拍照,但我从相机拍摄的每张照片都太大了。
最佳答案
你的代码对我来说看起来有点鱼,我会这样做:
var post:PFObject
func prepareToSavePost(){
post = PFObject(className: "Posts")
post["Contact"] = contactText.text
post["Name"] = nameOfPost.text
post["Description"] = descriptionOfPost.text
let imageData = UIImagePNGRepresentation(self.imageToPost.image)
let imageFile = PFFile(name: "image.png", data: imageData)
post["imageFile"] = imageFile
post["createdBy"] = PFUser.currentUser()?.objectId
//Get bytes size of image
var imageSize = Float(imageData.length)
//Transform into Megabytes
imageSize = imageSize/(1024*1024)
println("Image size is \(imageSize)Mb")
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, error: NSError?) -> Void in
if error == nil {
self.post.setValue(geoPoint, forKey: "Location")
println("found location")
savePost()
}
}
}
func savePost(){
post.saveInBackgroundWithBlock{
(success:Bool, error:NSError?)-> Void in
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if success == false{
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
self.displayAlert("Sorry! We could not post.", error: "Please try again later.")
}
//--NO ERRORS SO NOW WE CAN SAVE AND POST==\\
else{
self.performSegueWithIdentifier("backToFeed", sender: self)
}
}
}
}
我为什么要这么做?看来您可以在尝试同时更新位置和其他详细信息时遇到死锁,换句话说,在后台并行运行两次保存命令。
这能解决您的问题吗?也许,parse.com 并不总是按实际情况发送错误
我还添加了图像大小的日志,但您可以在 if 中对其进行转换,并弹出警报 View ,或者如果图像大于 10Mb 则调整图像大小(我认为 iPhone 中不会发生这种情况)
关于ios - parse 和 swift 的 PFFile 大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990701/
我得到了“从 PFFile 到 PFFile 的条件转换总是成功”的提示,它突出显示了 if let tempProductPicture = self.askProductImageArray[0]
从 Parse 检索图像并将其显示在 tableView 上,如果我向下滚动 tableView,应用程序崩溃并给出“ fatal error :数组索引超出范围” 行数由“messagesArray
我想从磁盘获取 PFFile。我在这里了解到 Parse 会在下载所有 PFFile 时对其进行缓存。我现在想知道如何检索该缓存。什么是正确的路径。我使用的路径建议here NSString *pat
我正在尝试根据附加到我从中提取 imageFile 的同一对象的 objectID 检索 PFFile 图像。所有其他细节都被正确拉取(字符串),但是,当我拉取 PFFile 时,会加载该类中的随机图
解析仪表板版本 1.1.2 解析服务器版本2.7.1 环境设置 在 Ubuntu 16.4( digital ocean Droplet)上运行的 Parse-Dashboard 重现步骤 添加新的文
是否可以在运行 Parse Server 的 mlab.com/heroku 中的一个字段名下保存一组图像。我试图在一个字段名称中保存 150 张图像。我知道如何保存一张图片。但是是否有可能在一个字段
我在使用我的 iOS 应用程序从我的数据库中上传的 PFFile 的 URL 流式传输视频时遇到问题。我使用了 Heroku 和 AWS,但我仍然遇到同样的问题。当文件托管在旧的解析服务器中时,它过去
Parse.com 刚刚更新了他们的 SDK 以支持本地存储。但是在安装新的 SDK 之后,PFFile 出现了一些问题。我已经使用相同的方法很长时间了,但是现在我使用的是新的 SDK,我无法让它工作
我正在使用 Parse,并且有一个名为“GolfScorecard”的类,该类有多个键,其中包括一个“scorecardImage”键,它是一个 PFFile。我正在尝试将所有高尔夫记分卡信息显示在
我有一个 UItextView,我可以在其中放置图像并输入文本,一旦完成 TextView,我就会将该 textView 的内容上传到 Parse。 如果我只向 textView 添加 1 个图像,它
我在我的 iOS 应用程序中使用核心数据实现了一个本地数据库,该数据库从由 Parse 驱动的后端填充。 我想要一个 Core Data 实体,它的属性是 PFFile(一个解析文件对象)。 Core
这是我加载图片的方式: func LoadImage(sender:FeedVC, cellId:Int){ self.currentlyLoading = true let quer
我上传了一个 PFFile 到 Parse.com,并保存了 PFFile 的 url。然后我删除了 PFFile,并尝试使用保存的 url 下载 PFFile。成功了! 所以我的问题是:Parse.
在我的聊天应用程序中,我对用户表使用 Parse,获取 ID、图像等。我最近添加了此功能,但遇到了一个问题。当我发送消息时,我创建了一个 NSDictionary,其中包含有关消息的信息,例如时间、消
我已经在这个问题上停留了很长一段时间,我阅读了很多线程,但没有一个描述了我的问题我尝试了一大堆不同的方法来解决这个问题,但没有一个奏效。我有一个从数组中提取并通过 segue 发送到下载详细信息 Vi
我正在尝试使用解析从指针获取图像。我正在尝试从类中提取图像而不发出第二个请求。 这是代码: PFFile * connectImageFile = [object objectForKey:@"pra
我想在一个 PFFile 中保存 2 个数据:一个图像和一个数据声音。这对于图像 (fileData) 来说是正确的,但我想在 Parse.com 中为数据声音 (fileData2) 添加一列。我怎
这是我的 NGINX 设置, HTTPS 服务器 server { listen 443 ssl spdy; location /myparseserver/ {
我正在为我的应用程序使用 Parse 和 MongoDB,但我有一个关于 PFFile 的问题。我想在服务器上保存一个空的 PFFile。事实上,用户不必发送图片,但可以通过其他方式发送。 我想设置一
基本上我正在努力解决这个问题:我安装了一个 FacebookAlbumPicker ( https://github.com/OceanLabs/FacebookImagePicker-iOS ) 现
我是一名优秀的程序员,十分优秀!