Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Simple Web snapshot import java.util.Date; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.graphics.GC; import org.e... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data....
Stats
Output a file like url via routing
Prepare a binary output action for file output
[RoutePrefix("images")]
public class ImageController : Controller
{
    // GET: ~/images/profile.png
    // GET: ~/images/1873429732.jpg
    [HttpGet]
    [Route("{name}.{ext}")]
    public ActionResult ReadImage(string name, string ext)
    {
        if (System.IO.File.Exists(Server.MapPath(string.Format("~/uploads/{0}.{1}", name, ext))))
        {
            byte[] data = System.IO.File.ReadAllBytes(Server.MapPath(string.Format("~/uploads/{0}.{1}", name, ext)));
            string contentType = MimeMapping.GetMimeMapping(System.IO.Path.GetFileName(string.Format("{0}.{1}", name, ext)));
            return File(data, contentType);
        }
        else
        {
            return new HttpStatusCodeResult(404);
        }
    }
}

Then try test it, but respone 404 not found.




Add runAllManagedModulesForAllRequests="true" on modules section.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <system.webServer>
    ...
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
    </modules>
  </system.webServer>
  ...
</configuration>

Then try it again, image rendered success.


Install subversion with apache server on linux (ubuntu)
# 更新 apt package
sudo apt-get update
# 安裝 package
sudo apt-get install subversion apache2 libapache2-svn apache2-utils
# 建立 svn 資料夾
sudo mkdir -p /svn/repos/
# 建立 svn 使用者 (apache)
sudo mkdir -p /svn/users/
# 建立使用者(第一次時有參數-c)
sudo htpasswd -cm /svn/users/svnpasswd nanashi07
# 刪除使用者後再重建(重設密碼)
#sudo htpasswd -D /svn/users/svnpasswd nanashi07
#sudo htpasswd -m /svn/users/svnpasswd nanashi07
# 修改 apache 設定
sudo vi /etc/apache2/mods-enabled/dav_svn.conf
<Location /svn>
  DAV svn
  SVNParentPath /svn/repos/
  AuthType Basic
  AuthName "SVN Repository"
  AuthUserFile /svn/users/svnpasswd
  Require valid-user
</Location>
# 修改 apache 監聽埠
sudo vi /etc/apache2/ports.conf
# 重新啟動 apache
sudo service apache2 restart
# 建立資源庫
sudo svnadmin create /svn/repos/myproject
# 設定資源庫權限
sudo chown -R www-data:www-data /svn/repos/myproject
# 設定資源庫權限
sudo chmod -R g+rws /svn/repos/myproject
Add file to google drive
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SyncDump
{
    class Program
    {
        /// <summary>
        /// 存取權限
        /// </summary>
        static string[] Scopes = { DriveService.Scope.Drive, DriveService.Scope.DriveFile };
        static string ApplicationName = "Drive Uploader";

        static void Main(string[] args)
        {
            // 檢查輸入參數
            if (args.Length < 1)
            {
                Console.WriteLine("No target file argument!");
                return;
            }

            // 要上傳的檔案
            string dumpPath = args[0];
            string dumpName = System.IO.Path.GetFileName(dumpPath);

            // 載入驗證資訊
            GoogleCredential credential;
            using (var stream = new System.IO.FileStream("client_secret.json", System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream);
            }

            // 建立 service
            DriveService service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential.CreateScoped(Scopes),
                ApplicationName = ApplicationName
            });
            
            // 進行上傳
            insertFile(
                service,
                dumpName,
                dumpName,
                System.Configuration.ConfigurationManager.AppSettings["drive.folder.id"],
                "application/oct-stream",
                dumpPath
            );
        }

        /// <summary>
        /// 新增檔案
        /// </summary>
        /// <param name="service">Drive API service instance.</param>
        /// <param name="title">Title of the file to insert, including the extension.</param>
        /// <param name="description">Description of the file to insert.</param>
        /// <param name="parentId">Parent folder's ID.</param>
        /// <param name="mimeType">MIME type of the file to insert.</param>
        /// <param name="filename">Filename of the file to insert.</param><br>  /// <returns>Inserted file metadata, null is returned if an API error occurred.</returns>
        private static File insertFile(DriveService service, string title, string description, string parentId, string mimeType, string filename)
        {
            // 檔案資訊
            File body = new File();
            body.Title = title;
            body.Description = description;
            body.MimeType = mimeType;

            // 設定上傳位置
            if (!string.IsNullOrEmpty(parentId))
            {
                body.Parents = new List<ParentReference>() { new ParentReference() { Id = parentId } };
            }

            // 檔案內容
            byte[] byteArray = System.IO.File.ReadAllBytes(filename);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
            try
            {
                FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType);
                request.Upload();

                File file = request.ResponseBody;

                Console.WriteLine("{0:yyyy/MM/dd HH:mm:ss} File {1} is uploaded to drive", DateTime.Now, file.Title);

                return file;
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
                return null;
            }
        }
    }
}