How to get the file creation date even before it is saved in the file system in Python?

Viewed 18

In our application, we upload an audio file and then process it. I however want the file creation date before it is saved to the s3 bucket. While I can read the creation date, but the moment it is upload, the creation date changes to the current date and time. I need the original date for sure. So it means, I need to read the file metadata even before the metadata is changed.

I am using Python code for this purpose. Can someone give some pointers on how to achieve this functionality in Python.

1 Answers

The creation date is generated by the bucket. You shouldn't be able to get the creation date before you upload.

Closest alternative I can think of is to use the metadata tag e.g x-goog-meta-creation and store your own creation date

policy_fields['x-goog-meta-creation'] = datetime.now()
policy = storage_client.generate_signed_post_policy_v4(
        bucket,
        blob_name,
        conditions=conditions,
        expiration=datetime.timedelta(minutes=expiration),
        fields=policy_fields,
    )

Or you will have to read the data after upload to get the actual datetime

Related