After some quick searching I do not see any straightforward was to go about that. What I would do is:
- Create a new field for a
PFUser
called usedSpace
. This will be the amount of megabyte a user is able to have.
- Create a new Cloud Code function that accepts both an image and an image file size.
- When you go to upload, you can find the file size in megabytes by following this answer.
- Pass the image data and file size to your new function.
- In your new function check to see if the user has enough free space to save the new image. If so, save and update the
usedSpace
parameter. If not, return an error.
You Cloud Code function would look something like this (pseudo-ish code):
// For example:
Parse.Cloud.define("saveImageWithSize", function(request, response) {
// Grab var's from params
var imageData = request.params.imageData;
var imageSize = request.params.imageSize;
if user has enough free space {
// save the imageSize
// update the `usedSpace` field
response.success("success");
}
else user does not have enough space {
response("not enough space");
}
});
Then you would call it from your app like this:
PFCloud.callFunctionInBackground("saveImageWithSize", withParameters: ["imageData" : yourImageData, "imageSize" : youImageSize]) { (response, error) in
if let err = error {
print(err)
}
else {
print(complete)
}
}
hope this helps.