Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Credentials argument to CreateFromUrl #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions src/WordPressSharp/Models/MediaUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,28 @@ public static Data CreateFromFilePath(string path, string mimeType)
return data;
}

/// <summary>
/// Creates the data structure from the URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="mimeType">Type of the MIME. If <c>null</c> the ContentType header of the url will be used.</param>
/// <returns>
/// The data structure.
/// </returns>
/// <exception cref="System.ArgumentException">Url is a required parameter.</exception>
public static Data CreateFromUrl(string url, string mimeType = null)
{
if (url == null)
{
throw new ArgumentException("Url is a required parameter.", "url");
}

var bytes = new byte[0];

using (WebClient wc = new WebClient())
{
Data data = new Data();
/// <summary>
/// Creates the data structure from the URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="mimeType">Type of the MIME. If <c>null</c> the ContentType header of the url will be used.</param>
/// <returns>
/// The data structure.
/// </returns>
/// <exception cref="System.ArgumentException">Url is a required parameter.</exception>
public static Data CreateFromUrl(string url, string mimeType = null, NetworkCredential credential = null)
{
if (url == null)
{
throw new ArgumentException("Url is a required parameter.", "url");
}

var bytes = new byte[0];

using (WebClient wc = new WebClient())
{
if (credential != null) wc.Credentials = credential;
Data data = new Data();
data.Bits = wc.DownloadData(url);
data.Name = Path.GetFileName(url);

Expand Down