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

  • Home
  • SEARCH
  • 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 8985823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:24:38+00:00 2026-06-15T21:24:38+00:00

This is my API method which uploads the .caf file to the server, converts

  • 0

This is my API method which uploads the .caf file to the server, converts into .mp3 and deletes the .caf file. But the problem is that both the original file and the converted file are being deleted instead of only the original file.

[HttpPost]
    [ActionName("UploadCompetitionEntry")]
    public async Task<HttpResponseMessage> UploadCompetitionEntry([FromUri]string folderName)
    {
        if (!Request.Content.IsMimeMultipartContent())
        {
            throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
        }

        string path = System.Web.Hosting.HostingEnvironment.MapPath("~/" + folderName);

        MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(path);
        var task = Request.Content.ReadAsMultipartAsync(provider);

        // Log exceptions
        await task.ContinueWith(t =>
        {
            if (t.IsFaulted)
            {
                // Log t.Exception
            }
        });           

            var bodyPart2 = provider.FileData.Where(p => p.Headers.ContentDisposition.Name.Replace("\"", string.Empty) == folderName).FirstOrDefault();

            if (bodyPart2 != null)
            {
                string savedFile2 = bodyPart2.LocalFileName;
                string originalFile2 = bodyPart2.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
                string uniqueFilename = string.Format(@"{0}", Guid.NewGuid());
                string newFile2 = uniqueFilename + Path.GetExtension(originalFile2);

                // Copy file and rename with new file name and correct extension
                FileInfo file2 = new FileInfo(savedFile2);
                file2.CopyTo(Path.Combine(path, newFile2), true);
                file2.Delete();


                if (folderName == "music")
                {
                    //converting .caf to .mp3 and creating a new .mp3 file
                    MediaFuncs.ConvertToMp3(Path.Combine(path, newFile2), uniqueFilename);

                    //deleting the .caf file
                    FileInfo file3 = new FileInfo(Path.Combine(path, newFile2));
                    file3.Delete();
                }
            }         


        return Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage<Object> { success = true, message = "Media Uploaded" });

    }   

And this is my converter method

 public static void ConvertToMp3(string filename, string uniqueFilename)
    {
        string musicPath = System.Web.Hosting.HostingEnvironment.MapPath("~/" + "music");

        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

        info.FileName = System.Web.Hosting.HostingEnvironment.MapPath("~/" + "ffmpeg.exe");
        info.Arguments = " -i " + filename + " " + Path.Combine(musicPath, uniqueFilename + ".mp3");

        System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(info);
    }

Am i doing something wrong? If anyone knows any other way to delete just the original file, please please let me know, i have been banging my head about it all day 🙁

EDIT: I put a breakpoint and checked. I think am deleting the .caf file before the conversion is complete. Because when i put the breakpoint just after calling the converter method and before deleting the file, the .mp3 wasnt deleted.

So now how do i stall the deleting till the conversion is complete?

  • 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-06-15T21:24:39+00:00Added an answer on June 15, 2026 at 9:24 pm

    You need to wait for the conversion to finish before deleting the source file.

    To do that, you can simply call:

    p1.WaitForExit();
    

    At the end of ConvertToMp3.

    See WaitForExit on MSDN.

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

Sidebar

Related Questions

I am trying to upload a pdf file using webservice api. But this api
I'm trying to use depedency resolver inside a Web Api method. This worked fine
I'm having some trouble with Mongodb and Python (Flask). I have this api.py file,
If I use the ImageShack API just in a form like this: <form method=post
I'm implementing an API an have a method which you pass a list of
I'm writing an API and I'm wanting to handle file uploads from a form
Is there a Apache Commons / Log4J logging API method which can be used
I need to send a file from one PHP page (on which client uploads
I wrote small FTP Client Applet which uploads files to FTP Server using Commons
I have Hibernate method which returns me a BigDecimal. I have another API method

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.