Skip to content

Commit 698f8f9

Browse files
author
Amir Tocker
committed
Merge branch 'RTLcoil-features/new-features'
2 parents 834e2c3 + 2d853e7 commit 698f8f9

File tree

4 files changed

+1260
-1234
lines changed

4 files changed

+1260
-1234
lines changed

Cloudinary.Test/CloudinaryTest.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,13 +587,28 @@ public void TestUploadLargeRawFiles()
587587
// support uploading large raw files
588588

589589
var largeFilePath = m_testPdfPath;
590-
590+
int fileLength = (int)new FileInfo(largeFilePath).Length;
591591
var result = m_cloudinary.UploadLargeRaw(new BasicRawUploadParams()
592592
{
593593
File = new FileDescription(largeFilePath)
594594
});
595595

596-
Assert.AreEqual(new FileInfo(largeFilePath).Length, result.Length);
596+
Assert.AreEqual(fileLength, result.Length);
597+
}
598+
599+
[Test]
600+
public void TestUploadLarge()
601+
{
602+
// support uploading large image
603+
604+
var largeFilePath = m_testImagePath;
605+
int fileLength = (int)new FileInfo(largeFilePath).Length;
606+
var result = m_cloudinary.UploadLarge(new BasicRawUploadParams()
607+
{
608+
File = new FileDescription(largeFilePath)
609+
}) as ImageUploadResult;
610+
611+
Assert.AreEqual(fileLength, result.Length);
597612
}
598613

599614
[Test]

Cloudinary/Actions/RawUploadParams.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,20 @@ public class FileDescription
208208
internal bool EOF = false;
209209
internal int BytesSent = 0;
210210

211-
internal bool IsLastPart()
211+
internal long GetFileLength()
212212
{
213213
long len = 0;
214214

215215
if (m_stream != null)
216216
len = m_stream.Length;
217217
else
218218
len = new FileInfo(m_path).Length;
219+
return len;
220+
}
219221

220-
return len - BytesSent <= BufferLength;
222+
internal bool IsLastPart()
223+
{
224+
return GetFileLength() - BytesSent <= BufferLength;
221225
}
222226

223227
/// <summary>

Cloudinary/Api.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static Api()
6464
/// Assumes that environment variable CLOUDINARY_URL is set.
6565
/// </summary>
6666
public Api()
67-
: this(Environment.GetEnvironmentVariable("CLOUDINARY_URL")) { }
67+
: this(Environment.GetEnvironmentVariable("CLOUDINARY_URL")) { }
6868

6969
/// <summary>
7070
/// Parameterized constructor
@@ -302,7 +302,7 @@ public static T ParseCloudinaryParam<T>(string s)
302302
/// <param name="parameters">Dictionary of call parameters (can be null)</param>
303303
/// <param name="file">File to upload (must be null for non-uploading actions)</param>
304304
/// <returns>HTTP response on call</returns>
305-
public HttpWebResponse Call(HttpMethod method, string url, SortedDictionary<string, object> parameters, FileDescription file)
305+
public HttpWebResponse Call(HttpMethod method, string url, SortedDictionary<string, object> parameters, FileDescription file, Dictionary<string, string> extraHeaders = null)
306306
{
307307
#if DEBUG
308308
Console.WriteLine(String.Format("{0} REQUEST:", method));
@@ -311,7 +311,6 @@ public HttpWebResponse Call(HttpMethod method, string url, SortedDictionary<stri
311311

312312
HttpWebRequest request = RequestBuilder(url);
313313
request.Method = Enum.GetName(typeof(HttpMethod), method);
314-
315314
// Add platform information to the USER_AGENT header
316315
// This is intended for platform information and not individual applications!
317316
request.UserAgent = string.IsNullOrEmpty(UserPlatform)
@@ -322,10 +321,16 @@ public HttpWebResponse Call(HttpMethod method, string url, SortedDictionary<stri
322321
{
323322
request.Timeout = Timeout;
324323
}
325-
326324
byte[] authBytes = Encoding.ASCII.GetBytes(String.Format("{0}:{1}", Account.ApiKey, Account.ApiSecret));
327325
request.Headers.Add("Authorization", String.Format("Basic {0}", Convert.ToBase64String(authBytes)));
328326

327+
if (extraHeaders != null)
328+
{
329+
foreach (var header in extraHeaders)
330+
{
331+
request.Headers[header.Key] = header.Value;
332+
}
333+
}
329334
if ((method == HttpMethod.POST || method == HttpMethod.PUT) && parameters != null)
330335
{
331336
if (UseChunkedEncoding)

0 commit comments

Comments
 (0)