Source folder for files upload API?

I'm trying to utilise APIs that upload files to existing studio projects which are published to Groupshare; however, I'm not sure how to locate the source folder where I should put the files in.

Here are the APIs I'm trying to use:

POST /api/projectserver/v2/projects/{projectId}/files/upload

PUT /api/projectserver/v2/projects/{projectId}/files/{languageFileId}/upload

POST /api/projectserver/v4/projects/{projectGuid}/update

POST /api/projectserver/v4/projects/{projectId}/files/upload/perfectmatch

Please note that I'm trying to use my machine not the console's environment.

emoji
Parents
  • Hi ,  instead of providing a source folder, you should provide the data bytes of the file/s you are communicating to the API endpoint.  The following is an example of how you might go about this.

            // Replace these values with actual values
            string baseUrl = "https://example.com/api/projectserver/v2/";
            string projectId = "yourProjectId";
            string languageFileId = "yourLanguageFileId";
            string filePath = "path_to_your_file.txt"; // Path to the file you want to upload
    
            using (var httpClient = new HttpClient())
            {
                // Prepare the request URL
                string apiUrl = $"projects/{projectId}/files/{languageFileId}/upload";
                string requestUrl = new Uri(new Uri(baseUrl), apiUrl).ToString();
    
                // Read the file into a byte array
                byte[] fileBytes = File.ReadAllBytes(filePath);
    
                // Create the content for the HTTP request
                using (var content = new MultipartFormDataContent())
                {
                    content.Add(new ByteArrayContent(fileBytes), "file", Path.GetFileName(filePath));
    
                    // Send the POST request
                    HttpResponseMessage response = await httpClient.PostAsync(requestUrl, content);
    
                    // Process the response
                    if (response.IsSuccessStatusCode)
                    {
                        Console.WriteLine("File uploaded successfully.");
                    }
                    else
                    {
                        Console.WriteLine($"File upload failed. Status code: {response.StatusCode}");
                    }
                }
            }

    let me know how it goes,

Reply
  • Hi ,  instead of providing a source folder, you should provide the data bytes of the file/s you are communicating to the API endpoint.  The following is an example of how you might go about this.

            // Replace these values with actual values
            string baseUrl = "https://example.com/api/projectserver/v2/";
            string projectId = "yourProjectId";
            string languageFileId = "yourLanguageFileId";
            string filePath = "path_to_your_file.txt"; // Path to the file you want to upload
    
            using (var httpClient = new HttpClient())
            {
                // Prepare the request URL
                string apiUrl = $"projects/{projectId}/files/{languageFileId}/upload";
                string requestUrl = new Uri(new Uri(baseUrl), apiUrl).ToString();
    
                // Read the file into a byte array
                byte[] fileBytes = File.ReadAllBytes(filePath);
    
                // Create the content for the HTTP request
                using (var content = new MultipartFormDataContent())
                {
                    content.Add(new ByteArrayContent(fileBytes), "file", Path.GetFileName(filePath));
    
                    // Send the POST request
                    HttpResponseMessage response = await httpClient.PostAsync(requestUrl, content);
    
                    // Process the response
                    if (response.IsSuccessStatusCode)
                    {
                        Console.WriteLine("File uploaded successfully.");
                    }
                    else
                    {
                        Console.WriteLine($"File upload failed. Status code: {response.StatusCode}");
                    }
                }
            }

    let me know how it goes,

Children