Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
AWSS3GetObjectRequest.ifModifiedSince does not seem to be working

I'm not able to get ifModifiedSince to work. Here is my code:

func updateDatabase()
{
    let objectRequest = AWSS3GetObjectRequest()
    objectRequest?.key = "wa/wa2016/idahoGmu.tiff"
    objectRequest?.bucket = bucketName

    let dateComponents = NSDateComponents()
    dateComponents.day = 10
    dateComponents.month = 4
    dateComponents.year = 2018
    let date = NSCalendar.current.date(from: dateComponents as DateComponents)

    // TODO This isn't working.  It grabs the file regardless of date.
    objectRequest?.ifModifiedSince = date

    let s3 = AWSS3.default()

    s3.getObject(objectRequest!).continueWith
    {
        (task) -> AnyObject! in if let error = task.error
        {
            print("Error: \(error.localizedDescription)")
        }

        if let result = task.result
        {
            let fileManager = FileManager.default
            let documents = Bundle.main.resourcePath
            let writePath = documents?.appending("/Content/idahoGmu.tiff")
            let output = result as AWSS3GetObjectOutput

            let fileData = output.body as! Data
            fileManager.createFile(atPath: writePath!, contents: fileData, attributes: nil)
        }

        return nil;
    }
}

Is there something I am doing wrong with formatting the date? I read this issue about the date format (but it is reported as fixed now): AWSS3GetObjectRequest ifModifiedSince not working

When I print out the date it looks like this:

2018-04-10 07:00:00 +0000

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Maybe do you can replace ifModifiedSince to AWSS3HeadObjectRequest(), for example:

// create a date to compare
let formatter = DateFormatter()
formatter.dateFormat = "yyyy/MM/dd"
let checkDate = formatter.date(from: "2016/10/08")

// make a request to AWS S3, to get a info of file
let request = AWSS3HeadObjectRequest()!
request.bucket = bucket
request.key = key
AWSS3.default().headObject(request).continue({
    task -> Any? in

    if let result = task.result,
      ((result as AWSS3HeadObjectOutput) != nil) {

        let servDate = result.lastModified!
        if checkDate < servDate {
            // my file was modified after 2016/10/08
        } else {
            // my file was NOT modified after 2016/10/08
        }
    }
 }

You can see a example where. I use something similar to create a cache system, in checkDownloadCache(bucket:key) function.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!