Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add time stamp to photo upload

I am uploading a photo from my iOS app to my server. Currently I am hard coding the name of the photo that I am uploading but this causes all subsequent photos to be overwritten (naturally). To combat this I would like to create a new name for the image, preferably by adding a header (which I define in a separate text field) as well as a timestamp of when it was uploaded. My attempts at this code are as follows, however they do not work :P ...

NSString * timestamp = [NSString stringWithFormat,[[NSDate date], timeIntervalSince1970] * 1000];
        var header:NSString = txtHeader.text
        let filename = (header)&&(timestamp)&&"image.jpg"
        let mimetype = "image/jpg"
like image 981
Saucepan Avatar asked Nov 25 '25 17:11

Saucepan


1 Answers

something like

var currentTimeStamp = String(Int(NSDate().timeIntervalSince1970))

can also add

extension Double {
    func format(f: String) -> String {
        return NSString(format: "%\(f)f", self) as String
    }

    func toString() -> String {
        return String(format: "%.1f",self)
    }

    func toInt() -> Int{
        var temp:Int64 = Int64(self)
        return Int(temp)
    }
}

var currentTimeStamp = NSDate().timeIntervalSince1970.toString()

edit: filename

let filename = "\(header)_\(currentTimeStamp)_img.jpg"
like image 186
Daniel Krom Avatar answered Nov 28 '25 08:11

Daniel Krom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!