[ 
https://issues.apache.org/jira/browse/HDFS-8678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15616328#comment-15616328
 ] 

Ivo Udelsmann commented on HDFS-8678:
-------------------------------------

Hello,

After reading the previous comment I took the liberty of adding the 
functionality to "head" the file in the available patch. Unfortunately I'm not 
able to attach the patch I generated. 

I'm adding it to this comment since it is very short and could spare someone 
the time to implement it.

Thank you. 

{code}
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html
index ad8c374..3700a5e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.html
@@ -57,8 +57,17 @@
            <h4 class="modal-title" id="file-info-title">File information</h4>
          </div>
          <div class="modal-body" id="file-info-body">
-           <a id="file-info-download">Download</a>
-        <!--<a id="file-info-preview" style="cursor:pointer">Tail the file 
(last 32K)</a>-->
+           <div class=row>
+              <span class="col-xs-4">
+                <a id="file-info-download">Download</a>
+              </span>
+              <span class="col-xs-4">
+                <a id="file-info-preview-head" style="cursor:pointer">Head the 
file (first 32K)</a>
+              </span>
+              <span class="col-xs-4">
+                <a id="file-info-preview-tail" style="cursor:pointer">Tail the 
file (last 32K)</a>
+             </span>
+           </div>
            <hr />
            <div class="panel panel-success" id="file-info-blockinfo-panel">
              <div class="panel-heading">
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js
index 1739db2..3e276a9 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js
@@ -192,13 +192,40 @@
       var download_url = '/webhdfs/v1' + abs_path + '?op=OPEN';

       $('#file-info-download').attr('href', download_url);
-      $('#file-info-preview').click(function() {
+
+      var processPreview = function(url) {
+        url += "&noredirect=true";
+        $.ajax({
+          type: 'GET',
+          url: url,
+          processData: false,
+          crossDomain: true
+        }).done(function(data) {
+          url = data.Location;
+          $.ajax({
+            type: 'GET',
+            url: url,
+            processData: false,
+            crossDomain: true
+          }).complete(function(data) {
+            $('#file-info-preview-body').val(data.responseText);
+            $('#file-info-tail').show();
+          }).error(function(jqXHR, textStatus, errorThrown) {
+            show_err_msg("Couldn't preview the file. " + errorThrown);
+          });
+        }).error(function(jqXHR, textStatus, errorThrown) {
+          show_err_msg("Couldn't find datanode to read file from. " + 
errorThrown);
+        });
+      }
+
+      $('#file-info-preview-tail').click(function() {
         var offset = d.fileLength - TAIL_CHUNK_SIZE;
         var url = offset > 0 ? download_url + '&offset=' + offset : 
download_url;
-        $.get(url, function(t) {
-          $('#file-info-preview-body').val(t);
-          $('#file-info-tail').show();
-        }, "text").error(network_error_handler(url));
+        processPreview(url);
+      });
+      $('#file-info-preview-head').click(function() {
+        var url = d.fileLength > TAIL_CHUNK_SIZE ? download_url + '&length=' + 
TAIL_CHUNK_SIZE : download_url;
+        processPreview(url);
       });

       if (d.fileLength > 0) {
{code}

> Bring back the feature to view chunks of files in the HDFS file browser
> -----------------------------------------------------------------------
>
>                 Key: HDFS-8678
>                 URL: https://issues.apache.org/jira/browse/HDFS-8678
>             Project: Hadoop HDFS
>          Issue Type: Sub-task
>          Components: ui
>            Reporter: Ravi Prakash
>            Assignee: Ravi Prakash
>         Attachments: HDFS-8678.01.patch, HDFS-8678.02.patch
>
>
> The legacy file browser displayed small chunks of a file in the browser 
> itself. This was useful to users because they can quickly verify that their 
> input or output is in the format they expect. We should bring back this 
> functionality.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to