Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6599247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:27:56+00:00 2026-05-25T18:27:56+00:00

I am saving a file to a server and I’m saving the filename, user

  • 0

I am saving a file to a server and I’m saving the filename, user id of the individual who uploaded the file, and various other information about the file to a PostgreSQL database. I ideally want to structure this in a way that is similar to a database transaction. That is, one of the following should occur:

  1. Save file
  2. If successful, save information to database
  3. If saving information to database fails, delete file

OR

  1. Save information to database
  2. If successful, save file
  3. If saving file fails, delete information from database

The only problem with this methodology is step 3 may fail–that is, you may be left with a file saved without corresponding information in the database or you may have database information without a corresponding file saved.

What I want to know is if there is a way that you can use either of the two methods above while ensuring step 3 always occurs or occurs with sufficient reliability that I effectively do not have to worry about failure.

Note that I am using a PostgreSQL database and saving an image file using the imagegif, imagejpeg, and imagepng functions from the GD library.

EDIT

In response to Jack’s solid comments below, I forgot to mention that I am interacting with the DB through an API server, so instead of directly interacting with the DB, I am sending REST requests to the API which in turn interacting with the DB. What this effectively means is that I can’t just put both database interactions into one transaction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:27:56+00:00Added an answer on May 25, 2026 at 6:27 pm

    I decided to choose a sub-optimal but still workable route of running a periodic check that searches for database entries for every filename and if a database entry cannot be found, then the file is deleted. (If anyone is actually interested in the code details, I will gladly provide it in an edit.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am saving a .doc file to a SQL Server database as varbinary(max) using
I am saving all the words from a file like so: sentence = fileName
I am downloading a file from an ftp server and saving it to the
I am releasing a database build to SQL Server 2000 via a batch file
Before saving an uploaded csv file I want to check it will parse. When
I am saving an image file at server. The file is successfully saved at
Using MSXML4, I am creating and saving an xml file: MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc; //add some
Saving data to Postscript in my app results in a Postscript file which I
Iam trying to saving an UIImage in PDF file. How can i do this?
I wonder when saving plot into image file in matlab, what is the difference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.